How it works...

The above recipe shows how to use destructuring syntax to create individual variables for elements in an array. The destructuring syntax mirrors the indices of the corresponding array. So, variable names will be associated with the element at the corresponding position in the array. The name at the zeroth position will be assigned a value at the beginning of the array. The name at position 1 will be assigned the value at the next, and so on.

So we can see above that we name each of the elements in the rockets array. The value of each of the extracted elements is a match for the corresponding rocket.

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.