Combine or merge JSON on node.js without jQuery

后端 未结 18 1966
醉话见心
醉话见心 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:02

    There is an easy way of doing it in Node.js

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

    To combine/extend this we can use ... operator in ECMA6

    var object1 = {name: "John"};
    var object2 = {location: "San Jose"};
    
    var result = {
      ...object1,
      ...object2
    }
    
    console.log(result)

提交回复
热议问题