Combine or merge JSON on node.js without jQuery

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

    A better approach from the correct solution here in order to not alter target:

    function extend(){
      let sources = [].slice.call(arguments, 0), result = {};
      sources.forEach(function (source) {
        for (let prop in source) {
          result[prop] = source[prop];
        }
      });
      return result;
    }
    

提交回复
热议问题