Khoa Nguyen
Pressure creates diamonds
Skip to main content

JavaScript Advanced Concept Spread Syntax

Last updated:

Spread Syntax

The Spread syntax ... is a relatively new operator that was introduced in ES2018. It provides a concise way to combine objects and arrays.

const obj = { 
    foo: 1, 
    bar: 2, 
    baz: 3 
};
const newObj = {
    foo: 4,
    ...obj,
};
console.log(newObj); // { foo: 1, bar: 2, baz: 3 } the old foo is overwritten

It’s also useful for combining arrays.

const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const arr3 = [...arr1, ...arr2];
// arr3 will be [1,2,3,4,5,6]
  • Design Thinking
  • Usability
  • Accessibility
  • Information Architecture
  • Wireframe
  • Responsive Design