Destructuring
Destructuring is an ES6/ES2015 feature. Destructuring allows us to break down the complex data structure into a simple data structure. In general, we use this in an array and objects.
Array Destructuring:
Let us consider an array
To get an individual array value we can assign a value directly to the variable.
The above expression can give the value as in the log if we console the value of x, y, z.
the above method is used to assign values / get values from array till ES6/ES2015.
The Array restructuring is the ES6 method, the above method is done with simple code.
This can be done in a nested array also
Similarly, we can extract the required value from the given array. For an instance, we want only the first value and the last value from the given array. We can simply give a hole while we assign variables to the array values. So that unwanted variables can be ignored.
These kinds of assignments will help us to retrieve or return specific data with ease using array destructuring.
Thank you!!!
Have a good day!!!
No comments:
Post a Comment