Search code examples
javascripttypescriptdestructuring

JS: Use array destructuring (eslintprefer-destructuring)


I am getting the ESLint error (Use array destructuring. eslint(prefer-destructuring)) when I do:

let foo = 1;
foo = obj.data[i][1]; //ESLint error on this line

Can anyone please help to fix this?


Solution

  • ESlint wants you to write

    let foo = 1;
    [, foo] = obj.data[i];
    

    Whether that's actually better if up to you to decide. If you don't like it, turn off that rule instead.