Combine or merge JSON on node.js without jQuery

后端 未结 18 2066
醉话见心
醉话见心 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 17:54

    You can do it inline, without changing any variables like this:

    let obj1 = { name: 'John' };
    let obj2 = { surname: 'Smith' };
    let obj = Object.assign({}, obj1, obj2); // { name: 'John', surname: 'Smith' }
    

提交回复
热议问题