how to add two objects in javascript code example
Example 1: how to add two attay into object in javascript
var keys = ['foo', 'bar', 'baz'];
var values = [11, 22, 33]
var result = Object.assign.apply({}, keys.map( (v, i) => ( {[v]: values[i]} ) ) );
console.log(result);
Example 2: merge two objects javascript
const object1 = {
name: 'Flavio'
}
const object2 = {
age: 35
}
const object3 = {...object1, ...object2 }
Example 3: javascript merge objects
var person={"name":"Billy","age":34};
var clothing={"shoes":"nike","shirt":"long sleeve"};
var personWithClothes= Object.assign(person, clothing);
Example 4: merge two objects javascript
Object.assign(target, sourceObj1, sourceObj2, ...);
Example 5: how to merge two objects into one in javascript
let obj1 = { foo: 'bar', x: 42 };
let obj2 = { foo: 'baz', y: 13 };
let clonedObj = { ...obj1 };
let mergedObj = { ...obj1, ...obj2 };
Example 6: merge objects js
Object.assign(obj1, obj2);
const allRules = Object.assign({}, obj1, obj2, obj3, etc);