JavaScript sorting array from nested array?
Posted
by
Tim
on Stack Overflow
See other posts from Stack Overflow
or by Tim
Published on 2013-10-18T21:50:12Z
Indexed on
2013/10/18
21:54 UTC
Read the original article
Hit count: 173
JavaScript
|arrays
I have an array:
letterFrequency = [["a", 12], ["b", 25], ["c", 34], ["d", 1], ["e", 35], ["f", 8], ["g", 7], ["h", 67], ["i", 35], ["j", 0], ["k", 53], ["l", 0], ["m", 0], ["n", 3], ["o", 0], ["p", 0], ["q", 3], ["r", 153], ["s", 0], ["t", 0], ["u", 15], ["v", 0], ["w", 0], ["x", 3], ["y", 0], ["z", 0]]
and I want to sort it in descending order based on the number within the nested array i.e. letterFrequency[i][1]
. So I want the most popular letter to be first. How would I do this?
© Stack Overflow or respective owner