How can I sort 2D array with JavaScript?
I have any array like this:
arr = [["123", "2017-07-11 15:00", '1'],
["124","2017-07-04 16:00", '1'],
["125","2017-07-05 12:00", '1'],
["126","2017-07-04 21:00", '1'],
["127","2017-07-03 02:00", '1'],
["128","2017-07-05 11:00", '1'],
["129","2017-07-05 14:00", '1']]
And I want to sort by the second element (arr[1]) How Can I do that?
I tired this before:
let b = arr.map(x=> x[1]).sort();
console.log(b);
And this is my console result:
["2017-07-03 02:00",
"2017-07-04 16:00",
"2017-07-04 21:00",
"2017-07-05 11:00",
"2017-07-05 12:00",
"2017-07-05 14:00",
"2017-07-11 15:00"]
But this is my expected result:
[["127", "2017-07-03 02:00", '1'],
["124","2017-07-04 16:00", '1'],
["126","2017-07-04 21:00", '1'],
["128","2017-07-05 11:00", '1'],
["125","2017-07-05 12:00", '1'],
["129","2017-07-05 14:00", '1'],
["123","2017-07-11 15:00", '1']