• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

135
Views
eslint showing unexpected use of comma, no-sequences for an array

I have the following code, and eslint keeps showing no-sequences warning.

const full = {};

["firstname", "lastname", "spouse"].forEach(key => {
})

["cellphone", "phone"].forEach(key => {
})

Though the error is on the second forEach block, the warning only appears when I put the first forEach block. is this an eslint bug?

here is the link on eslint demo editor

almost 3 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Since your code has no semicolon, you're basically trying to access an array in the first forEach:

["firstname", "lastname", "spouse"].forEach(key => {
})["cellphone", "phone"].forEach(key => {
})

Of course this is not correct. To fix this problem, just add a semicolon:

["firstname", "lastname", "spouse"].forEach(key => {
}); // Add a semicolon here

["cellphone", "phone"].forEach(key => {
}); // Here it is not necessary, but it is a good practice to avoid that kind of error

This will fix the error because semicolons point out the end of a statement, so ESLint will be able to understand that there are two different statements.

almost 3 years ago · Juan Pablo Isaza Report

0

You are missing a semi-colon at the end of the first forEach call, so your code is equivalent to:

["firstname", "lastname", "spouse"].forEach(key => {
})["cellphone", "phone"].forEach(key => {})

That is attempting to get the value of the "phone" property of the return value of forEach (which is undefined). [] is interpreted to be bracket notation instead of an array literal due to automatic semicolon insertion. ESLint is pointing out the use of the comma operator in "cellphone", "phone", which results in attempting to read the "phone" property.

almost 3 years ago · Juan Pablo Isaza Report

0

I didn't know object value access is actually multiline.

const data = {"key":123}

console.log(

  data

  ["key"]

)

Though on newline, Would actually work and print access data["key"] to print 123.

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error