Array and object destructuring helps code be more clear and flexible, this syntax will let you decompose arrays and objects straightforward, we can now return multiple values with less work, there is few things you can do in different ways.
Let’s see some examples:
A nice way to split an array into single objects.
You have different semantic ways of obtaining values from an object which can definitely simplify things.
Note: The name of the key you are assigning has to be the same, otherwise, will throw undefined.
Destructuring a function
Returning multiple objects is much easier when you descompose them.
You can go deeper and use destructuring with nested objects or arrays.
Note how easy we got electrodomestic instead of doing something like:
A value source could be listed multiple times, for example:
The assigment expression with objects or arrays has as completition value, the full righthand object/array value.
Problaby one of the most powerfull and usefull features in ES6 is that you can pass arrays and objets as parameters to a function which will help you avoid using apply or call.