I am pretty new to eslint and I am updating my code to fit my eslint file.
module.exports = {
env: {
browser: true,
commonjs: true,
node: true,
es2021: true,
},
extends: 'eslint:recommended',
parserOptions: {
ecmaVersion: 'latest',
},
rules: {
indent: ['error', 2],
'linebreak-style': ['error', 'unix'],
quotes: ['error', 'single'],
semi: ['error', 'always'],
},
};
I have a for loop and eslint is saying that 'i' is not defined.
for (i = 0; dbl.length > i; i++) {
arr.push(dbl[i].Author);
}
To my knowledge when using a for loop you are supposed to init a var in the first part, however I'm not sure.
Am I doing for loops wrong or is there something I am missing with eslint?
All help is appreciated, thank you!
You have to declare the variable first. Follow the code below.
for (let i = 0; dbl.length > i; i++) {
arr.push(dbl[i].Author);
}
I think you got the point.
You problem is unrelated to eslint. You need to define i before you can use it.
// note the `let` before the `i`
for (let i = 0; dbl.length > i; i++) {
arr.push(dbl[i].Author);
}