0

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?

1 Answer 1

1

You can use Array.prototype.filter()

Like this

$scope.SACDescription = function(code) {
     return $scope.SACCodes.filter(function(x){ return x.code == code; });
}

DEMO

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.