I have an array like this:
let pairs = [[2,"test"], [7,"buzz"], [3,"asd"]]
How can i sort the outer array by the first values? (descending)
I have an array like this:
let pairs = [[2,"test"], [7,"buzz"], [3,"asd"]]
How can i sort the outer array by the first values? (descending)
Pass a compare function to Array.sort that examines the first element in each array, to determine the required order.
> let pairs = [[2,"test"], [7,"buzz"], [3,"asd"]]
> pairs.sort((a, b) => a[0] - b[0]);
[ [ 2, 'test' ], [ 3, 'asd' ], [ 7, 'buzz' ] ]