Search code examples
javascripteslintdestructuring

Eslint asking to destructure array.split()?


Eslint is asking me to use array destructuring on the following statement:

sessID = sessID.split('.')[0].split(':')[1];

How could you possibly destructure something like this? All I'm doing is extracting a substring out of a bigger string using split(). It's the split() function that's turning the string into an array, right?


Solution

  • Linters provide tips for the general case. You can safely ignore these tips if appropriate, as in this case. This won't be easier to read with array destructuring. Proof:

     ([, sessID] = sessID.split('.')[0].split(':'));