Destructuring is an elegant way to extract data from arrays and objects. It removes excessive and repetitive use of indexing operators or dots to get to the data within arrays and objects. The notation takes a bit of getting used to, but soon you’ll be quite comfortable making use of it in your own code and also recognizing its use in code you read.

Array Destructuring

Functions typically return a single value: a primitive or an object. There is no elegant way to return multiple values other than returning an array. That makes the code within the function easy to write, but it turns the code on the receiving end messy. Let’s take a look at an example.

Here’s a function that returns an array.


Get Rediscovering JavaScript now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.