Object.keys(arrayObject).map(key=>arrayObject[key]).reduce((old,item)=>(
{...old,...item}
),{})
let arr1 = [
{ id: "abdc4051", date: "2017-01-24" },
{ id: "abdc4052", date: "2017-01-22" }
];
let arr2 = [
{ id: "abdc4051", name: "ab" },
{ id: "abdc4052", name: "abc" }
];
let arr3 = arr1.map((item, i) => Object.assign({}, item, arr2[i]));
console.log(arr3);
Run code snippet
var arr1 = [{name: "lang", value: "English"},{name: "age", value: "18"}];
var arr2 = [{name : "childs", value: '5'}, {name: "lang", value: "German"}];
Array.prototype.push.apply(arr1,arr2);
console.log(arr1); // final merged result will be in arr1
/*
[{"name":"lang","value":"English"},
{"name":"age","value":"18"},
{"name":"childs","value":"5"},
{"name":"lang","value":"German"}]
*/
const arrObj = [{a: 1, b: 2}, {c: 3, d: 4}, {e: 5, f: 6}];
console.log(arrObj.reduce(function(result, current) {
return Object.assign(result, current);
}, {}));
// If you prefer arrow functions, you can make it a one-liner ;-)
console.log(arrObj.reduce(((r, c) => Object.assign(r, c)), {}));
// Thanks Spen from the comments. You can use the spread operator with assign
console.log(Object.assign({}, ...arrObj));
Run code snippet