Wednesday, 15 March 2017

Merge two objects and ignore unique keys

I have two objects original and custom. I want to merge custom to original, but ignore the keys from original that are not found in custom object. For example:

var original = {

    coupon: {
            coupon: "Coupon",
            couponTypes: {
                single: "Single",
            }
        },

    language: {
            Language: "Language",
            chooseLanguage: "Choose your language",
            }

        }


 var custom = {

    coupon: {
        coupon: "Coupon Details",
        couponTypes: {
            single: "Single Coupon",
        }
    }   
}

The expected result should be like this:

 var result = {

     coupon: {
            coupon: "Coupon",
            couponTypes: {
                single: "Single",
            }
        }   
    }

It should replace only the values for those keys which exists in custom object and ignore the other.



via Georgi K.

No comments:

Post a Comment