I'm trying to avoid duplicates. If I send the same name (say, Jason) again, I don't want it to be added to the $scope.people for the second time. How can I check it before adding?
$scope.people = [
{
name : "Jason",
age : 26,
height : 176,
},
{
name : "Mark",
age : 34
height : 190
}
];
$scope.add = function(name,age,height) {
// How can I make sure that Jason or Mark won't get added again?
}
If it was a simple array, I would have solved it like below, but this is different.
$scope.add = function (name) {
if ($scope.people.indexOf(name) == -1) {
$scope.people.push(name);
}
};