Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Sort objects of objects by nested property

var data = { player1: { score: 4, cards: 6 }, player2: { score: 6, cards: 4 } },
    sorted = {};

Object
    .keys(data).sort(function(a, b){
        return data[b].score - data[a].score;
    })
    .forEach(function(key) {
        sorted[key] = data[key];
    });

console.log(sorted);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Sort #objects #objects #nested #property
ADD COMMENT
Topic
Name
4+9 =