How to do it...

  1. Open your command-line application and navigate to your workspace.
  2. Create a new folder named 06-10-spread-operator-combine.
  3. Copy or create an index.html that loads and runs a main function from main.js.
  4. Create a main.js file with an async function named main, which creates a couple of objects and a constant. It then uses the spread operator and object structuring to combine them into a single object:
// main.jsexport function main() { 
  const object1 = { 
    prop1: 'some value', 
    prop2: 'some other value', 
  } 
  const object2 = { 
    prop2: 'some overriding value', 
    objectProp: { foo: 'bar' } 
  } 
  const anotherProp = Math.random(); 
 
  const combinedObject = { ...object1, ...object2, anotherProp }; 
  console.log(combinedObject); 
} 
  1. Start your Python ...

Get ECMAScript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.