Update values from one json object to another in node JS

This question already has an answer here:

  • How can I merge properties of two JavaScript objects dynamically? 55 answers

  • Simple for loop

    for (var key in j2) { j1[key] = j2[key]; }
    

    Demo: http://jsfiddle.net/tymeJV/kthVf/


    yes, you can implement your own function of inheritance :

    function inherits(base, extension)
                {
                    for (var property in base)
                    {
                        try
                        {
                            extension[property] = base[property];
                        }
                        catch(warning)
                        {
                        }
                    }
                };
    

    then

    inherits(j2,j1)
    console.log(j1)
    // Object {name: "Varun", age: 24, code: "NodeJS", alter: "C++"}
    
    链接地址: http://www.djcxy.com/p/27332.html

    上一篇: 不能在构造函数中赋值

    下一篇: 将节点JS中的一个json对象更新为另一个json对象