Within one of the controllers in my Angular application, I have set a variable like this:
SomeService.get({}, function(data){
// This assigns xyz as the data list retrieved from the
// resource within the controller's scope
$scope.xyz = data.objects;
});
Now, $scope.xyz
looks something similar to this:
[
0: {id: 1, ...more data here ...},
1: {id: 2, ...more data here ...},
2: {id: 3, ...more data here ...},
3: {id: 4, ...more data here ...},
4: {id: 5, ...more data here ...},
5: {id: 6, ...more data here ...},
]
I am attempting to retrieve an object within xyz using the id
property (not the index in the list). I know I can loop through the array like so:
angular.forEach($scope.xyz, function(obj){ return obj.id == 1;});
However, is there a way to achieve this without looping through the list?