Destructring In Javascript

Destructuring assignment is used to unpack value from an array, or properties from the object, into distinct variables

Let [x,y] = [7,20]

x will be assigned 7 and y, 20

[10,x, ...rest] =

[10, 80, 7, 11, 21, 88] x will be 80 rest will be [7,11,21,88]

Similarly, we can destructure objects on the left-hand side of the assignment

let [a, b, c, d, ...rest] = arr

console.log(a, b, c, d, ...rest)

let [a, , , ...rest] = arr

console.log(a, rest)

Thank you for reading this. If you like this article, please give it a thumbs up and share it. Also, feel free to leave comments below

https://www.buymeacoffee.com/junoriver88

2
Subscribe to my newsletter

Read articles from Siddharth Kanojiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Siddharth Kanojiya
Siddharth Kanojiya

I am very passionate Coder https://www.buymeacoffee.com/junoriver88