I have following 2D array: [["fox", "100"], ["the", "1"], ["quick", "50"]]
And want to store only the first element of the array, but sorted based on the second value.
Desired output: the,quick,fox
I have written a loop that iterates over the first elements which seems to work, however I cannot get it sorted based on the second value:
for (var i = 0; i < inputArr.length; i++) {
x1 += inputArr[i][0];
if(i != inputArr.length - 1){
x1 = x1 + ",";
}
}
Write(x1); //outputs -> fox,the,quick
inputArr.sort((a,b) => a[1]-b[1]).map(([a]) => a).flat().join(',')- flat might be unneeded though...