Monday, February 25, 2019

How can I merge properties of two JavaScript objects dynamically?

I need to be able to merge two (very simple) JavaScript objects at runtime. For example I'd like to:



var obj1 = { food: 'pizza', car: 'ford' }
var obj2 = { animal: 'dog' }


obj1.merge(obj2);

//obj1 now has three properties: food, car, and animal


Does anyone have a script for this or know of a built in way to do this? I do not need recursion, and I do not need to merge functions, just methods on flat objects.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...