JavaScript sorting array from nested array?
- by Tim
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?