Skip to content

JavaScript:Rest/Spread

Dictionary 병합/분해시 사용하는 ... 문법. (e.g. let food = {...a,...b})

Rest

let { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
x; // 1
y; // 2
z; // { a: 3, b: 4 }

Spread

Using ES6 Spread operator

let a = {};
a['fruit'] = "apple";

let b = {};
b['vegetable'] = "carrot";

let food = {...a,...b}

console.log(food)

See also

Favorite site