Javascript: Sort array of arrays by second element in each inner array

Here is a concrete, working example, using Array.prototype.sort:

const arr = [
  [500, 'Foo'],
  [600, 'bar'],
  [700, 'Baz']
];

arr.sort((a,b) => a[1].toUpperCase().localeCompare(b[1].toUpperCase()));

console.log(arr);

Leave a Comment