Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to merge two object arrays in javascript

var objArr1 = [{id: "1", fruit: "apple"},{id: "2", fruit: "banana"}];
var objArr2 = [{id : "3", fruit: 'mango'}, {id: "4", fruit: "pear"}];

Array.prototype.push.apply(ObjArr1,ObjArr2); 

console.log(ObjArr1);  // final merged result will be in ObjArr1
// ObjArr1 => [{id: "1", fruit: "apple"},{id: "2", fruit: "banana"},{id : "3", fruit: 'mango'}, {id: "4", fruit: "pear"}]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #merge #object #arrays #javascript
ADD COMMENT
Topic
Name
4+5 =