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

343
Views
ESLint Warning: Use array destructuring

Why do I get the ESLint warning Use array destructuring for the following line?

tmpObj[item].sample = urls[key][0];
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You must be having the prefer-destructuring flag on in your config. Destructuring was added as a part of ES6.

From the docs about the rule:

With JavaScript ES6, a new syntax was added for creating variables from an array index or object property, called destructuring. This rule enforces the usage of destructuring instead of accessing a property through a member expression.

The rule considers this as incorrect:

// With `array` enabled
var foo = array[0];
// With `object` enabled
var foo = object.foo;
var foo = object['foo'];

And this as correct:

// With `array` enabled
var [ foo ] = array;
var foo = array[someIndex];

// With `object` enabled
var { foo } = object;

In your case, the below should do it. You are still accessing the first element this way.

[tmpObj[item].sample] = urls[key];

PS : You can always switch off the flag.

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!