Skip to content
Advertisement

How can I ignore certain returned values from array destructuring?

Can I avoid declaring a useless variable when array destructuring when I am only interested in array values beyond index 0?

In the following, I want to avoid declaring a, I am only interested in index 1 and beyond.

JavaScript

Advertisement

Answer

Can I avoid declaring a useless variable when array destructuring when I am only interested in array values beyond index 0?

Yes, if you leave the first index of your assignment empty, nothing will be assigned. This behavior is explained here.

JavaScript

You can use as many commas as you like wherever you like, except after a rest element:

JavaScript

The following produces an error:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement