Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

append object to object javascript

// Spread syntax allows an iterable (in this case an object) to be expanded

const originalObj = { name: 'John', age: 34 }
let newObj = { ...originalObj, city: 'New York' }
// newObj is now { name: 'John', age: 34, city: 'New York' }

// it can also be used with the same object
newObj = { ...newObj, language: 'en' }
// { name: 'John', age: 34, city: 'New York', language: 'en' }
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #append #object #object #javascript
ADD COMMENT
Topic
Name
9+6 =