Table of contents
Destructuring
- The main goal of restructuring is to convert it into smaller objects.
How does this work
- Place the element that you want to destructure on the right-hand side of ' equals to '
- const [ myarray1, myarray2 ] = [1,2,34] Based on the position of the element in the array to the left of the equal to the same number element will be assigned to it
Note: 1. What I mean is myarray1 is the first element of the array.
2. Hence the first element of the array on the right side of equal to will be assigned to it
- Using the rest operator with array destructuring.
const [ myarray1,...rest]=[1,2,3,4]
Now myarray1 will have the value of the first element of the array ie: myarray1 will be equal to 1. and now whatever is left those s elements 2,3,4 will be assigned to rest
Object destructring
- As in array destructuring we are doing it based on the elements of the array , so now in object the only difference is we will be doing it on the basis of the object key_value