Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

435
Views
eslint for loop 'i' is not defined

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!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report

0

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); 
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!