So I have the following javascript object generated by the server. The object is called $scope.activityResults
[{
id: 2010,
updateId: 1,
userId: 2,
points: 10
}, {
id: 2011,
updateId: 2,
userId: 3,
points: 100
}];
I then have a newly created item, and I want to determine whether the userId exists in the object or not. If the userId exists, I want to do X, if they don't exist I want to do Y.
var newResult = {
id: 0,
updateId: 3,
userId: 10,
competitionId: "2014354864",
result: $scope.activityPointsValue,
time: new Date()
}
I'm struggling to figure out the best way to check whether the userId already exists in the object or not.
Would LOVE some help.
if (newResult.userId exists in $scope.activityResults)) { //This line needs the help :)
console.log("You already have some points");
} else {
console.log("Didnt find you, adding new row :)");
}