0

I want to append an object of objects to another object of objects like so:

object1: {
   item1: {},
   item2: {}
}

to 

object2: {
   item3: {},
   item4: {}
}

So that the outcome is this:

object1: {
   item1: {},
   item2: {},
   item3: {},
   item4: {}
}

I need to do this in javascript and can also use lodash as an option.

AngularM
  • 15,982
  • 28
  • 94
  • 169
  • 3
    Before asking trivial questions such as this one, please read the docs, search using google, and then search again (research). – zzzzBov Aug 05 '16 at 14:14

1 Answers1

3

Use Object.assign() function:

Object.assign(object1, object2);

Also, to make in portable, you can use lodash lib:

_.assign(object1, object2);

If you want to create new object, instead of mutating existing one, you can provide {} as first argument:

_.assign({}, object1, object2);
1ven
  • 6,776
  • 1
  • 25
  • 39