Merge two JSON objects programmatically

后端 未结 8 989
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 02:01

I have two JSON objects here, generated through the Google Search API. The URL\'s of these objects can be found below.

http://ajax.googleapis.com/ajax/services/searc

8条回答
  •  暖寄归人
    2020-12-17 02:13

    Object.prototype.merge = (function (ob) {
        var o = this;
        var i = 0;
        for (var z in ob) {
            if (ob.hasOwnProperty(z)) {
                o[z] = ob[z];
            }
        }
        return o;
    })
    
    var a = {a:1}
    var b = {b:2}
    
    var c = a.merge(b); // === {a:1,b:2}
    

提交回复
热议问题