Using an angular array how do I add and remove elements between the two arrays?
I have $scope.results
and $scope.list
the results array is the result of a call to a WebAPI and i'm allowing the user to select the elements they want to add to the second array. How do i add from the first to the second and remove from the first at the same time?
angular.forEach($scope.results, function (item) {
if (item.selected) {
$scope.list.push(item);
//CODE TO REMOVE item from $scope.results here.
};
});
Additionally if i did a second search and tried to add the same member from the first array to my second array (which already had this user) how do i prevent adding duplicates to the second array (list)?.
below is a sample of the objects im wanted to transfer between the arrays. the id field is the indicator of uniqueness.