Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get single item from array through destructuring

Tags:

javascript

We have prefer-destructuring enabled in our ESLint rules and it is giving me an error on the line of code below, but I have no idea how to use destructuring in this particular case.

modifiedResults = partition[1];

So far I have tried:

[, modifiedResults, ] = partition;
[, modifiedResults, ...] = partition;
[, modifiedResults, ...rest] = partition;

None of these work, and for the last one it is telling me that rest is not defined, which is fair enough as I was intending it as a throw away variable.

Any ideas would appreciated...

like image 704
ovimunt Avatar asked Jun 24 '26 02:06

ovimunt


1 Answers

You first try should work and can be simplified as

let [, modifiedResults] = partition;

I did try it and it works, if it doesn't work it should be related to something else IMO

like image 52
Jiby Jose Avatar answered Jun 26 '26 15:06

Jiby Jose