Skip to main content

Command Palette

Search for a command to run...

Destructring In Javascript

Updated
•1 min read•View as Markdown
Destructring In Javascript
S

I am very passionate Coder

https://www.buymeacoffee.com/junoriver88

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