0

I have an array of objects matchedProfiles and I'm trying to order those objects by a property's value in them.

matched profiles = [ 

{
common: Array[1],
match: 8.333333333333329,
score1: Array[1],
score2: Array[1],
user1ID: "1116145178404907",
user2ID: "1710007182568600"
}, 

{
common: Array[1],
match: 25,
score1: Array[1],
score2: Array[1],
user1ID: "170401213316838",
user2ID: "1710007182568600"
}

]

I tried to order this array

var sortedMP = $filter('orderBy')(matchedProfiles, match);

but I'm getting an error in the console log

Uncaught ReferenceError: match is not defined

2 Answers 2

1

According to documentation https://docs.angularjs.org/api/ng/filter/orderBy you can pass expression as a string 'match'

var sortedMP = $filter('orderBy')(matchedProfiles, 'match');

or function

var sortedMP = $filter('orderBy')(matchedProfiles, function(profile) {
    return profile.match;
});
Sign up to request clarification or add additional context in comments.

Comments

1

Try like this

var sortedMP = $filter('orderBy')(matchedProfiles, 'match');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.