Merge 2 arrays of objects using JavaScript

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.
Deepak Sharma
Asked 18-04-2021
59

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.
Deepak Sharma
Asked 27-01-2020
45 Likes
Comments
Write comment

Submit your answer