D
D
DTX2017-01-24 14:59:46
JavaScript
DTX, 2017-01-24 14:59:46

How to fill one object with the properties of another?

There is an initial object:
obj1 = {a: 1, b: [], c: 'str'}
It is necessary to fill in all the properties of the second object into it:
obj2 = {a: 2, c: 'new str', d: 123}
To get either
{a: 2, b: [], c:'new str'}
or
{a: 2, b: [], c:'new str', d: 123}
What is the easiest way to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-01-24
@DirecTwiX

Something like this:
https://jsfiddle.net/qjszwq0h/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question