js merge 2 object code example
Example 1: merge objects javascript
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };
const ad = { ...a, ...d };
Example 2: javascript merge objects
var person={"name":"Billy","age":34};
var clothing={"shoes":"nike","shirt":"long sleeve"};
var personWithClothes= Object.assign(person, clothing);
Example 3: merge objects js
Object.assign(obj1, obj2);
const allRules = Object.assign({}, obj1, obj2, obj3, etc);
Example 4: javascript combine objects
const obj1 = {'a': 1, 'b': 2};
const obj2 = {'c': 3};
const obj3 = {'d': 4};
const objCombined = {...obj1, ...obj2, ...obj3};
Example 5: two object combine together javascript
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };
const ad = { ...a, ...d };
let objs = [{firstName: "Steven"}, {lastName: "Hancock"}, {score: 85}];
let obj = objs.reduce(function(acc, val) {
return Object.assign(acc, val);
},{});