Home > Software design >  Merge Two json array in one in Node Js
Merge Two json array in one in Node Js

Time:09-01

I have two json arrays like

var json1 = [{id:1, name: 'xxx' ...}]
var json2 = [{sec:'A', class_name:'xyz' ...}]

I want them merge in to single arrays

var finalObj = [{id:1, name: 'xxx' ...},{id:sec, name: class_name ...},{id:A, name: 'xyz' ...}... ]

CodePudding user response:

Try this to concatinate two arrays into one.

var finalObj = json1.concat(json2);

CodePudding user response:

I am not sure if I get this right as you have the properties of second array as values in the expected result, but if you want to merge both arrays you could use spread operator:

var finalObj = [...json1, ...json2]

  • Related