I think you want something like this:

arrays.sort((a,b) => a[0].localeCompare(b[0]))

More about localeCompare here

Answer from Radu Diță on Stack Overflow
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
Question about sorting 2D array - Curriculum Help - The freeCodeCamp Forum
July 30, 2022 - Lets say I have 2D array(example will be from one of the code prep challenges). let testArr = [ [ 88, 'Bowling Ball' ], [ 2, 'Dirty Sock' ], [ 3, 'Hair Pin' ], [ 5, 'Microphone' ], [ 3, 'Half-Eaten Apple' ], [ 7, 'Toothpaste' ] ] I want to sort it alphabetically, by the elements with indexes [1](or I can say strings).
Discussions

Sort 2D array alphabetically?
You'll probably have to use Array.sort_custom. https://docs.godotengine.org/en/stable/classes/class_array.html#class-array-method-sort-custom More on reddit.com
🌐 r/godot
4
4
January 31, 2023
javascript - How to sort 2 dimensional array by column value? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Turn scattered docs and code into trusted AI context. Explore the new Stack Internal platform More on stackoverflow.com
🌐 stackoverflow.com
jquery - How to sort multidimensional array in javascript - Stack Overflow
I want to sort the array alphabetically based on the third item of array i.e arry[n][2] More on stackoverflow.com
🌐 stackoverflow.com
How does this .sort / 2D array demo work?
How does this .sort / 2D array demo work · This code block breaks down the order of the .sort operation, but could someone walk me through how this is accomplished line by line · First, I’m not sure if this example is actually “the best” example to explain the order of how the sort ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
5
0
January 2, 2021
🌐
Reddit
reddit.com › r/godot › sort 2d array alphabetically?
r/godot on Reddit: Sort 2D array alphabetically?
January 31, 2023 -

The request is in the title. I can't seem to find anywhere how to rearrange a 2D in alphabetic order.

eg.

var data : Array = [

['Joseph', 100.90],

['Aaron', 78.0],

['Felix', 70.56],

['Alex', 390.00],

['Brian', 20.0]

]

var empty_array : Array

I want the new data in the empty_array to be:

empty_array = [

['Aaron', 78.0],

['Alex', 390.00],

['Brian', 20.0]

['Felix', 70.56],

['Joseph', 100.90]

]

What I want to do is rearrange the data array alphabetically and put them in the empty_array. The sort method is unfortunately a void return type. I'd imagine the for loop would be used in this case.

🌐
Davy's Blog
blog.hao909.com › home › sorting a two dimensional array in javascript
Sorting a two dimensional array in javascript | Davy's Blog
July 8, 2011 - <script type="text/javascript"> var aa =[["b",3],["a",4],["e",2],["d",1]]; aa.sort(function(x,y){return y[1]-x[1]}); // Array now becomes [["a",4],["b",3],["e",2],["d",1]] </script> Sorting a two dimensional array in alphabetical order
🌐
Coderwall
coderwall.com › p › 5fu9xw › how-to-sort-multidimensional-array-using-javascript
How to sort multidimensional array using javascript (Example)
February 25, 2016 - if( typeof helper == 'undefined' ) { var helper = { } ; } helper.arr = { /** * Function to sort multidimensional array * * <a href="/param">@param</a> {array} [arr] Source array * <a href="/param">@param</a> {array} [columns] List of columns to sort * <a href="/param">@param</a> {array} [order_by] List of directions (ASC, DESC) * @returns {array} */ multisort: function(arr, columns, order_by) { if(typeof columns == 'undefined') { columns = [] for(x=0;x<arr[0].length;x++) { columns.push(x); } } if(typeof order_by == 'undefined') { order_by = [] for(x=0;x<arr[0].length;x++) { order_by.push('ASC'); } } function multisort_recursive(a,b,columns,order_by,index) { var direction = order_by[index] == 'DESC' ?
Find elsewhere
🌐
DEV Community
dev.to › prakash1245 › javascript-sorting-multidimensional-array-5g23
JavaScript Sorting Multidimensional Array - DEV Community
June 1, 2025 - #webdev #programming #javascript #productivity · Sorting is a technique to arrange item to Increasing or Decreasing order · Sorting of item done by comparison of another item or element · Single Dimensional Array have sorted by javascript sort method · Single dimension array sorting output ·
🌐
W3Schools
w3schools.com › js › js_array_sort.asp
JavaScript Array Sort
ES2023 added the toSorted() method as a safe way to sort an array without altering the original array.
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
How does this .sort / 2D array demo work? - Curriculum Help - The freeCodeCamp Forum
January 2, 2021 - { sortRes[inc] = [a, b, a - b]; inc += 1; return a - b; }); var p = 0; for (var i = 0; i { p += 1; if (p
🌐
SitePoint
sitepoint.com › javascript
Problem sorting a two-dimensional array - JavaScript - SitePoint Forums | Web Development & Design Community
October 13, 2010 - JavaScript · rumremix · October 13, 2010, 1:04am · 1 · I am declaring a 2D array like this… · var myArray = []; myArray[0] = []; myArray[1] = []; So now the first dimension will have a size of two (0 or 1) and the second dimension will have an unlimited size. I want to sort this array by the integer values held in myArray[1], where x is any number between zero and the size of my result set.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.some()
JavaScript Array sort: Sorting an Array More Effectively
November 8, 2024 - To sort this array alphabetically, you need to use a custom comparator function to convert all elements to the same case e.g., uppercase for comparison, and pass that function to the sort() method.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript sorting multidimensional array
How to Sort Multidimensional Array in JavaScript | Delft Stack
February 2, 2024 - The function should use the rules below to internally sort each supplied array’s subarray. If the elements are neither M nor B, they should stay in their position. If the element is either M or B, they should be sorted alphabetically.
🌐
Stack Overflow
stackoverflow.com › questions › 51168768 › how-can-i-sort-2d-array-with-javascript
How can I sort 2D array with JavaScript? - Stack Overflow
// Input. const input = [["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']] // Sort. const sort = x => x.sort((A, B) => { const dateA = new Date(A[1]) const dateB = new Date(B[1]) return dateA - dateB }) // Output. const output = sort(input) // Proof. console.log(output) ... Array.prototype.sort() expects a number.
🌐
Scaler
scaler.com › home › topics › sort array alphabetically in javascript
Sort Array Alphabetically in JavaScript - Scaler Topics
May 4, 2023 - In JavaScript, there are various methods for sorting the different data types such as strings and integers. For example, an array of objects can be sorted using the sort() method and then retrieved in alphabetical order. It is possible thanks to the alphabet's index values.