es6 merge two objects code example
Example 1: merge two objects javascript
const object1 = {
name: 'Flavio'
}
const object2 = {
age: 35
}
const object3 = {...object1, ...object2 }
Example 2: merge two objects javascript
Object.assign(target, sourceObj1, sourceObj2, ...);
Example 3: merge objects javascript es6
const response = {
lat: -51.3303,
lng: 0.39440
}
const item = {
id: 'qwenhee-9763ae-lenfya',
address: '14-22 Elder St, London, E1 6BT, UK'
}
const newItem = { ...item, location: response };
console.log(newItem );