Search
 
SCRIPT & CODE EXAMPLE
 

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);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to customize js alert box 
Javascript :: gatsby new 
Javascript :: get promise result from json() javascript 
Javascript :: StatusBar 
Javascript :: add value to array javascript 
Javascript :: unsplash 
Javascript :: toast message angular 
Javascript :: get an array with unique values 
Javascript :: viewmodelprovider example 
Javascript :: jquery on wheel event 
Javascript :: get id from queryselector 
Javascript :: how to hide title bar react-navigation 
Javascript :: javascript click on all links 
Javascript :: create a form and submit it dynamically jquery 
Javascript :: input radio trigger select jquery 
Javascript :: javascript regex cheat sheet 
Javascript :: count array filter javascript 
Javascript :: javascript json append array 
Javascript :: firebase where or 
Javascript :: dynamic route vue 
Javascript :: how to show modal with jquery 
Javascript :: execute bash program using js 
Javascript :: bun create react app 
Javascript :: forjs check if key in json 
Javascript :: chart js change axis label 
Javascript :: eintegrity npm error 
Javascript :: object destructuring javascript 
Javascript :: get current location url javascript 
Javascript :: localstorage vs sessionstorage 
Javascript :: forming an object with reduce 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =