Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

merge array of objects javascript

Object.keys(arrayObject).map(key=>arrayObject[key]).reduce((old,item)=>(
          {...old,...item}
),{})
Comment

merge 2 array of object by key

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
Comment

Merge two array of Object in JavaScript

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"}]
*/
Comment

Merge array of objects into one object

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript find the smallest and biggest number in array 
Javascript :: can not find static files on multilevel routes in express js 
Javascript :: how to add datepicker in appended input 
Javascript :: generate history logs 
Javascript :: three.js first issue resolved awwwards merge webgl html worlds 
Javascript :: how to pass parameter in javascript function from html 
Javascript :: onclick clear input field javascript 
Javascript :: jquery meta characters escape 
Javascript :: javascript pure ajax promise 
Javascript :: multiple filter html table using javascript 
Javascript :: await multiple promises 
Javascript :: how to put value in arrar 
Javascript :: responsive varient in material ui 
Javascript :: circular objects javascript 
Javascript :: (error) => { console.log(error); } 
Javascript :: H.C.F Calculation Program 
Javascript :: create multidimensional array with foreach javascript 
Javascript :: combine 2 data in column 
Javascript :: palindromes array number 
Javascript :: Convert form data to JavaScript object with jQuery 
Javascript :: Function Returning This 
Javascript :: _.clone underscore 
Javascript :: Will Yield A "Function" 
Javascript :: vs code shortkey to launch snippet 
Javascript :: ticket 
Javascript :: ipinfo location javascript 
Javascript :: populate strapi v4 
Javascript :: nextjs youtube embed 
Javascript :: regex from 5 to 30 1 number 1 lower case and 1 upper case letter 
Javascript :: row no datatable 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =