1var dict = {
2 "x": 1,
3 "y": 6,
4 "z": 9,
5 "a": 5,
6 "b": 7,
7 "c": 11,
8 "d": 17,
9 "t": 3
10};
11
12// Create items array
13var items = Object.keys(dict).map(function(key) {
14 return [key, dict[key]];
15});
16
17// Sort the array based on the second element
18items.sort(function(first, second) {
19 return second[1] - first[1];
20});
21
22// Create a new array with only the first 5 items
23console.log(items.slice(0, 5));