Nodejs Object Merge merge(obj1, obj2)

Here you can find the source of merge(obj1, obj2)

Method Source Code

Object.merge = (obj1, obj2) => {
  var obj3 = JSON.parse(JSON.stringify(obj1)); 
  Object.keys(obj2).map((key) => obj3[key] = obj2[key]); 
  return obj3/* w ww  . ja  va 2  s  .  c  o  m*/
}

Related

  1. merge()
    Object.merge = function () {
        return [].reduce.call( arguments, function ( ret, merger ) {
            Object.keys( merger ).forEach(function ( key ) {
                ret[ key ] = merger[ key ];
            });
            return ret;
        }, {} );
    };
    
  2. merge(object1, object2)
    Object.merge = function(object1, object2) {
      var target = Object.clone(object1);
      Object.each(object2, function(key, value) {
        target[key] = value;
      });
      return target;
    };
    
  3. merge(opts)
    Object.prototype.merge = function(opts) {
      for (var p in opts) {
        if (opts.hasOwnProperty(p)) {
          this[p] = opts[p];
    };
    
  4. reverse_merge(opts)
    Object.prototype.reverse_merge = function(opts) {
      for (var p in opts) {
        if (opts.hasOwnProperty(p)) {
          if (this.hasOwnProperty(p)) {
            continue;
          this[p] = opts[p];
    };