Answer the question
In order to leave comments, you need to log in
How to properly sort objects by value?
Good afternoon. Is there a function that sorts an array by value?
Need to get:
var obj = {312312:10,3432423:2,123123:1};
Made:var obj = {123123:1,312312:10,3432423:2};
var sortable = [];
for (var vehicle in obj) {
sortable.push([vehicle, obj[vehicle]]);
}
sortable.sort(function(a, b) {
return a[1] - b[1];
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question