-3

In project there are two objects as below

Object 1

var mainObject = { 
                    'JobDetailID' :  2083,
                    'StartDateTime' : "2016/12/20 12:43:41 PM",
                    'EndDateTime' : "2016/12/20 12:43:41 PM",
                    'Enablechk' : 0,
                    'EAlert' : 0,
                 }

Object 2

var data = {
                    'TriggerType' : 1,
                    'MinuteEvery' : 13
                }

What i want is merging this two objects, so that the result look like as below

var totalData = {
                'JobDetailID' :  2083,
                'StartDateTime' : "2016/12/20 12:43:41 PM",
                'EndDateTime' : "2016/12/20 12:43:41 PM",
                'Enablechk' : 0,
                'EAlert' : 0,
                'TriggerType' : 1,
                'MinuteEvery' : 13
}

How to achieve this ?

Kishan
  • 350
  • 2
  • 10
  • 31

1 Answers1

2
var totalData = Object.assign(mainObject, data);

Note that this is a "destructive" (overwriting) update of mainObject. If you don't want mainObject to be modified, then do:

var totalData = Object.assign({}, mainObject, data);
Jonathan Eunice
  • 21,653
  • 6
  • 75
  • 77