Reputation: 3093
I have an array of objects like this:
$scope.SACCodes = [
{'code':'023', 'description':'Spread FTGs', 'group':'footings'},
{'code':'024', 'description':'Mat FTGs', 'group':'footings'}
]
I want to write a function to grab the description based on the code, something like this:
$scope.SACDescription = function(code) {
return $scope.SACCodes WHERE code=:code
}
I'm not sure of the proper syntax?
Upvotes: 0
Views: 38
Reputation: 25352
You can use Array.prototype.filter()
Like this
$scope.SACDescription = function(code) {
return $scope.SACCodes.filter(function(x){ return x.code == code; });
}
Upvotes: 1