Here is my dictionary:
const dict = {
"x" : 1,
"y" : 6,
"z" : 9,
"a" : 5,
"b" : 7,
"c" : 11,
"d" : 17,
"t" : 3
};
I need a way to sort my dict
dictionary from the least to the greatest or from the greatest to the least. Or even it would be fine I had an array with the sorted keys in it. But I do not know how to do such thing using javascript
. I have done it before using python
, like this:
import heapq
from operator import itemgetter
thirty_largest = heapq.nlargest(8, dict.iteritems(), key=itemgetter(1))
I have searched for it in Google and I found that arrays have sort()
function but not dictionaries. So my question is: How can I sort the dictionary or get top 5 biggest values in sort order?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…