Scenario 1
An API that i call returns an array with duplicates.
var array1 = [{id:1, foo:23},{id:1, foo:24},{id:1, foo:22},{id:2, foo:26},{id:3, foo:26}]; //example
Question 1 -> how do I eliminate the duplicates to get a desired result of:
var array2 = [{id:1, foo:23 },{id:2, foo:26},{id:3, foo:26}];
Scenario 2
In my pagination i would call a new set of array
var array1 = [{id:2, foo:27},{id:2, foo:28},{id:3, foo:29},{id:4, foo:28},{id:5, foo:23}]; //example
i then do a foreach loop, to push it to array2.
var array2 = [{id:1, foo:23},{id:2, foo:27},{id:3, foo:27}];
angular.forEach(array1, function(a){
array2.push(a)
});
Question 2 -> How do i prevent an object in array1 that exists in array2 from getting pushed.
desired result:
var array2 = [{id:1, foo:23},{id:2, foo:27},{id:3, foo:27},{id:4, foo:28},{id:5, foo:23}]