How should i merge 2 arrays of objects using JavaScript;
I am trying
var x= {"hello":"1", "hello2":"456"};
var y= {"hi1":"852", "hi2":"9632", "hi3":"75391}";
var z = x.concat(y);
but getting error.
Answer (1)
hi you can try
var x = [{"hello":"1", "hello2":"456"}];
var y = [{"hi1":"852", "hi2":"9632", "hi3":"75391}];
Array.prototype.push.apply(x,y);
console.log(x);
//x will print combined array;
workable and tested.