Answer the question
In order to leave comments, you need to log in
How to find identical elements (objects) of 2 arrays?
There are 2 arrays of different lengths, whose elements are objects. It would be desirable to receive result in the form of an array, with these elements. Here are 2 arrays:
var arr1 = [{timeFormat: "00:00", timestamp: 1443128400000}, {timeFormat: "00:15", timestamp: 1443129300000}, {timeFormat: "02:15", timestamp: 1443136500000}];
var arr2 = [{timeFormat: "00:00", timestamp: 1443128400000}, {timeFormat: "01:00", timestamp: 1443132000000}, {timeFormat: "02:15", timestamp: 1443136500000}];
Answer the question
In order to leave comments, you need to log in
Well, something like this:
[].push.apply(arr1, arr2);
console.log(arr1);
Array.prototype.merger = function(){
var arr = this.slice();
this.forEach.call(arguments, function(e){
arr.push.apply(arr, e);
});
return arr;
}
//Пример
arr1.merger(arr2, arr3, arr4);
//Новый массив, содержащий элементы arr1-4
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question