0
    equal_points = {18:[
    {'scored_goals':500,'lost_goals': 520,'team':'team A'},
    {'scored_goals':490,'lost_goals': 530,'team':'team B'},
    {'scored_goals':500,'lost_goals': 510,'team':'team C'},
    {'scored_goals':490,'lost_goals': 500,'team':'team D'}
    ]};
var tmp_scored = [];
angular.forEach(equal_points, function(item) {
        angular.forEach(item, function(team) {
            tmp_scored.push(team.scored_goals);
            console.log(tmp_scored);
        });
});

Hi,I would like sort object by scored but if they are equal then sort them by lost goals.How can I check which objects have the same values?

1 Answer 1

2

You can use the sort function of the Array to implement your sorting by scored_goals and also by lost_goals like:

var arr = [
  {'scored_goals':500,'lost_goals': 520,'team':'team A'},
  {'scored_goals':490,'lost_goals': 530,'team':'team B'},
  {'scored_goals':500,'lost_goals': 510,'team':'team C'},
  {'scored_goals':490,'lost_goals': 500,'team':'team D'}
];

arr.sort(function (a,b) {
  return a.scored_goals>b.scored_goals && (a.lost_goals>b.lost_goals );
});

You can read more about it here:

https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/sort

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

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.