I don't like the , ,
here:
let colors = [ "red", "green", "blue" ];
let [ , , thirdColor] = colors;
Can I use some placeholders characters? I'd rather not introduce unused variables, I just want to make the code look clearer. Right now the only thing I can think about are comments:
let [/*first*/, /*second*/, thirdColor] = colors;
Any better ideas?
There is no concept of a placeholder in JS. Often _
is used for this, but you can't actually use it more than once in one declaration:
let [_, secondColor] = colors; // OK
let [_, _, thirdColor] = colors; // error
Also, _
may actually be used in your code, so you'd have to come up with another name, etc.
The simplest way may be to access the third element directly:
let thirdColor = colors[2];
let {2: thirdColor, 10: eleventhColor} = colors;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With