Skip to content
dreamcode
dreamcode
Map
Destructure & spread
Lesson 19 of 48
+15 XP on finish
JAVASCRIPT CLIMBSChapter 4 · JS Collections Depth

Destructuring & Spread

Destructuring lets you unpack values from arrays or properties from objects directly into distinct variables. The spread operator ... lets you copy or combine collections easily.

Worked example

How it reads

  • const { name, mag } = star creates variables named name and mag from the keys of star
  • [...list1, 3, 4] spreads the elements of list1 into a new array
Cloud tip: Destructuring makes unpacking function arguments or component props extremely clean and concise.
index.js
JAVASCRIPT
real JavaScript, runs in your browser
Console
Run your code to see its output here.
YOUR TURN

Use the spread operator to make a copy of cloud with height changed to 6000, and log it: { shape: 'wispy', height: 6000 }.

Press Run to check your work.