If I have an array with elements like these:
var array = [["This should be last", 1],
["This should be first I think", 1],
["This is the middle one", 1]];
The second value in each sub-array, which is always 1 in this case, doesn't affect the sorting. Using .sort()
directly won't work for this situation. (Or maybe it will?)
My goal is to sort the array based on string length from largest to smallest. After sorting, it should appear like this:
var array = [["This should be first I think", 1],
["This is the middle one", 1]
["This should be last", 1]];
How can I achieve this sorting?