6

I have a line in code that looks like this:

const [full, text, url] = markdownLink.exec(match) || [null, null, '']

However I am not using full and the linter is giving me a warning.

Line 28: 'full' is assigned a value but never used

I'd like to declare the tuple like this, but I don't need full. Is there a syntactical way to fix this by skipping full?

ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • 2
    does `const [, text, url] = ...` work? – dev Aug 27 '19 at 14:42
  • Does this answer your question? [How can I ignore certain returned values from array destructuring?](https://stackoverflow.com/questions/46775128/how-can-i-ignore-certain-returned-values-from-array-destructuring) – seanplwong Apr 27 '21 at 14:53

2 Answers2

0

This warning is because your array destructuring is doing some affectations like full = null; which is not used later.

Array destructuring is quite sexy, but not always the solution. In your case simply access to the array in a classic way.

const arr = markdownLink.exec(match) || [null, null, ''];
const text = arr[1];
const url = arr[2];
Richard Haddad
  • 904
  • 6
  • 13