Q:

two object combine together javascript

const obj1 = {'a': 1, 'b': 2};
const obj2 = {'c': 3};
const obj3 = {'d': 4};

const objCombined = {...obj1, ...obj2, ...obj3};
1
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };

const ad = { ...a, ...d }; // { b: 1, c: 2, e: 1, f: 2 }
5
const a = { b: 1, c: 2 };
const d = { e: 1, f: 2 };

const ad = { ...a, ...d }; // { b: 1, c: 2, e: 1, f: 2 }


let objs = [{firstName: "Steven"}, {lastName: "Hancock"}, {score: 85}];

let obj = objs.reduce(function(acc, val) {
    return Object.assign(acc, val);
},{});
-1

New to Communities?

Join the community