I have an array with values like :
userID: ["55f6c3639e3cdc00273b57a5",
"55f6c36e9e3cdc00273b57a6", "55f6c34e9e3cdc00273b57a3"];
$scope.userList : [Object, Object, Object, Object, Object],
where each object has an ID property of which i am comparing.
I want to compare whether the each userID array value exist in userList array or not.
$scope.userInfo = function(userID) {
var userDetails = [];
for (var i = 0; i < $scope.userList.length; i++) {
(function(i) {
for (var j = i; j < userID.length; j++) {
if ($scope.userList[i]._id === userID[j]) {
userDetails.push($scope.userList[i]);
}
}
})(i)
}
return userDetails;
};
The problem i am facing is for each userID in the array, i want to compare it with all the items in userList object to match.
The above code is not working. Its not comparing each array values with the entire object.
for (var j = i;....) - I doubt thats what you intended to do