Reputation: 3159
I'm trying to merge 2 objects into an array. I have a structure like this:
The object could be an empty or may have data. I'm trying to combine the object from he self.series2
into self.series
, so as to look like:
where: the second object is the object from the self.series2
. Is it possible?
Js:
var series = [{
"Name": "abd",
"Surname": "Agrawal",
"id" : 7349879837,
"address" : "7923street"
}];
var series2 = [{
"Name": "abd23",
"Surname": "desia",
"id" : 7349879837,
"address" : "7923street"
}];
merge: function(){
var self = this;
var self.series = {};
//here im not sure how to do a `forEach` for 2 objects
$.each(series, function (i, o) {
$.extend(self.series, o)
});
$.each(series2, function (i, o) {
$.extend(self.series, o) // in this case it overwrites the first object with the second one.
});
});
How can i loop in through both the objects so that at the end in self.series
, i have both objects from series and series2?
Any ideasss??? Thanks!!
Upvotes: 0
Views: 732
Reputation: 1719
Seems you have two arrays, and want a merged one. So maybe you try with Array.concat?
var series = series1.concat(series2);
Upvotes: 3