how to sort a 2d array in javascript

Solutions on MaxInterview for how to sort a 2d array in javascript by the best coders in the world

showing results for - "how to sort a 2d array in javascript"
Yohan
23 Jan 2020
1var arr = [[12, 'AAA'], [12, 'BBB'], [12, 'CCC'],[28, 'DDD'], [18, 'CCC'],[12, 'DDD'],[18, 'CCC'],[28, 'DDD'],[28, 'DDD'],[58, 'BBB'],[68, 'BBB'],[78, 'BBB']];
2
3arr.sort(function(a,b) {
4    return a[0]-b[0]
5});
Leonardo
24 Aug 2020
1var arr = [[12, 'AAA'], [12, 'BBB'], [12, 'CCC'],[28, 'DDD'], [18, 'CCC'],[12, 'DDD'],[18, 'CCC'],[28, 'DDD'],[28, 'DDD'],[58, 'BBB'],[68, 'BBB'],[78, 'BBB']];
2
3arr.sort(function(a,b) {
4    return a[0]-b[0]
5});
6
queries leading to this page
sort javascript multidimensional arrayreverse sort multidimensional array jsjavascript multidimensional sortingsort 2 dimensional array javascriptjs order a 2d arraysort 2d array in javascriptsort two d array javascripthow to sort an multidimensional array in jsmultidimensional array javascript sortjs sort multidimensional arraytypescript sort multidimensional arrayjavascript sorting a 2d arrayjavascript sort multidimensional array objectjs 2d array sortsort multidimensional array based on integer jsjavascript sort two dimensional arraysort multidimensional array javascriptsorting multidimensional array javascriptsort array in node js with multidimensionalsort multidimensional array by number javascript2d array sorted jsjavascript sort 2 dimensional array by integer valuejs 2d sort arraysort items in a 2d array javascriptsort multidimensional array by value jssorting two dimensional arrays jssort a 2d array by the second value javascriptsort 2d array in javascript by 1st valuesort array 2 dimensional javascriptsort 2d array javascript by second element sort javascript multidimensional array of optionssort array 2 dimensional from min to max javascriptjs array sort by columnjavascript sort multidimensional array by columnsort by columns in matrix jsjavascript sort array by specific columnsort a 2d array javascript from high to low valuenodejs multidimensional array sortsort multidimensional array javascripthow to sort multidimensional dimensional array in javascriptsorting 2d array javascripttypescript sort number multidimensional arrayorder multidimensional array list with javascriptjs sort multi arraysort 2d array javascriptfunction in js to sort a 2d array with numberssort data in multi dimensional array jssort multidimensional array based on argument jsjavascript array sort by first columnsorting single dimensional array in javascripthow to sort a multidimensional array in javascripthow to order the 2d array data in javascriptsort a 2d array javascripthow to sort by one variable in a two dimensional array javascriptjs sort 2d array second elementsort multidimensional array jsjavascript sort multidimensional array alphabeticallyusing sort function to sort 2d array in javascriptsort multidimensional array js without sort functionsort 2d array according to value in jshow to sort a matrix in javascripjavascript array sortieren mehrdimensionalhow to sort a two dimensional array in javascriptjavascript sort multidimensional array descendingsort two dimensional array javascriptjs 2d array sort descjavascript sort 2d arrayhow to sort a 2d array in javascripttwo dimensional array sort in javascriptsort array multidimensional array by number javascriptorder numbers in multiple array javascriptsorting n dimensional array based on one value javascriptsorting two dimensional array javascriptsort multidimensional array by first value javascriptjavascript sort 2d array by valuehow to sort numbers in a 2d array in jsjs multidimensional array sort by column descarray multidimensional sort jssort multiple arraysorting two dimensional array in javascriptsort all columns in matrix jssort array by column javascriptsorting 2d array in javascriptsort matrix by column jssorting multidimensional array in javascriptjavascript sort 2d array of numberssort array in javascript in two conditionsjavascript sort multidimensional arraysorting a two dimensional array in javascriptsort array by alphabetical and covert to 2d array javascriptjavascript sort 2d array by indexhow to sort multidimensional array in javascriptjavascript sort 2d array second valuesort two dimensional number array javascri 5btjavascript sort multidimensional associative arrayjavascript 2d array rearrangeorder 2d array on vallue jssort in typescript multidimensional arraysoort 2d array of numbers jsmultidimension array sort javascript not workingjavascript sort 2 dimensional arraysort multidimensional array with length javascriptjavascript sort multidimensional array object valuesort all column in multidimensional array javascriptsort matrix all column jssort array multidimentional jsjavascript sort multidimensional array by keycan i apply sort on multi dimensional array javascriptsorting 2 dimensional array in javascriptmultidimensional array sort in javascriptd3 js sort 2d arrayhow to sort two dimensional array in javascripthow to sort a 2d list in javascriptsort an 2d array in javascripthow to sort an 2d array in angularnode sort nested arrayjavascript multidimensional array sortsort 2d array jsjavascript order multidimensional arrayhow to sort 2d array in javascriptjs sort 2d arrayjavascript sort two dimensional array by valueorder by array in typescript multidimensionalarray sort 2d array jsjavascript set multidimensional arraysort named multidimensional array javascriptmulti array sort javascriptmultidimensional array length sort in javascripthow to sort a 2d array in javascript