How to sort array by first item in subarray
array = [[2,text],[5,text],[1,text]];
array.sort(function(a,b){return a[0] - b[0]})
working of the sort function
if the function returns
- less than zero, sort a before b
- greater than zero, sort b before a
- zero, leave a and b unchanged with respect to each other
Additional information at source.
array = [[2,text],[5,text],[1,text]];
array.sort(function(a,b){return a[0] < b[0]})