javascript sort array of objects by key value
arr.sort((x, y) => x.distance - y.distance);
javascript sort array of objects by key value
arr.sort((x, y) => x.distance - y.distance);
sort object dictionary javscript
var dict = {
"x": 1,
"y": 6,
"z": 9,
"a": 5,
"b": 7,
"c": 11,
"d": 17,
"t": 3
};
// Create items array
var items = Object.keys(dict).map(function(key) {
return [key, dict[key]];
});
// Sort the array based on the second element
items.sort(function(first, second) {
return second[1] - first[1];
});
// Create a new array with only the first 5 items
console.log(items.slice(0, 5));
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us