I have an array with subarrays and wish to sort numerically and descending by the first item in the subarrays. So for example, I wish to take the following array"
array = [[2,text],[5,text],[1,text]]
and sort it to become
array = [[5,text],[2,text],[1,text]]
Is there any simple function to use? Thanks!
array = [[2,text],[5,text],[1,text]];
array.sort(function(a,b){return a[0] < b[0]})
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
Additional information at source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With