Destructuring and Spread
Pull values out of objects and arrays and copy or merge with spread.
Example
const { a, b = 2, ...rest } = { a: 1, c: 3, d: 4 };
const [x, , z] = [1, 2, 3];
console.log(a, b, rest, x, z);
console.log({ ...{ p: 1 }, q: 2 }, [...[1], 2]);Result
1 2 { c: 3, d: 4 } 1 3
{ p: 1, q: 2 } [ 1, 2 ]Exercise
Spread.
[arr, 4]
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.