Combine or merge JSON on node.js without jQuery

后端 未结 18 2056
醉话见心
醉话见心 2020-12-07 17:17

I have multiple JSON like those

var object1 = {name: \"John\"};
var object2 = {location: \"San Jose\"};

They are not nesting o

18条回答
  •  悲哀的现实
    2020-12-07 18:09

    Let object1 and object2 be two JSON object.

    var object1 = [{"name": "John"}];
    var object2 = [{"location": "San Jose"}];
    
    object1.push(object2);
    

    This will simply append object2 in object1:

    [{"name":"John"},{"location":"San Jose"}]
    

提交回复
热议问题