To sort an array of arrays in JavaScript, you can use the sort() method with a custom comparator. For example, to sort by the first element in each sub-array, use:
let arr = [[3, ‘a’], [1, ‘b’], [2, ‘c’]];
arr.sort((a, b) => a[0] – b[0]);
console.log(arr); // Outputs: [[1, ‘b’], [2, ‘c’], [3, ‘a’]]
You can adjust the comparator to sort by other elements in the sub-arrays. For instance, to sort by the second element, use a[1] and b[1] in the comparator function. The sort() method modifies the original array in place.