I have an array like this:
$scope.emails = [ {\"key\":\"Work\",\"value\":\"user@domine.com\"}, {\"key\":\"\",\"value\":\"\"}, {\"key\":\"Work\",\"value\":
indexOf returns -1 when it doesn't find an item.
indexOf
-1
A way to remove an item, and to avoid removing the last one when not found, is:
var index = $scope.items.indexOf($scope.oldItem); if (index != -1) { $scope.items.splice(index, 1); }