Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sort string 2d array in javascript

var arr1 = [[1, "Hair Pin"], [21, "Bowling Ball"], [2, "Dirty Sock"], [5, "Microphone"]];

arr1.sort(function (a, b) {
    return a[1].localeCompare(b[1]);
});

document.write('<pre>' + JSON.stringify(arr1, 0, 4) + '</pre>');
 Run code snippet
Comment

javascript sort multi-dimensional array

/*//*\___________________l4r3f4c3@proton.me________________/|**/
/**/  Array.prototype.sort2d = function(column) {              //
/**/  column = typeof column === "undefined" ? 0 : column      // 
/**/  return this.sort((a, b) => a[column]-b[column]); }       //
/**/  const unsorted2DArray = [[3,1,1,1],[9,3,3,3],[6,2,2,2]]  //
/**/  sorted2DArray = unsorted2DArray.sort2d()                 //
/**/  //sorted2DArray = [ [3,1,1,1],[6,2,2,2],[9,3,3,3] ]      //
/*//*======================/*//*/=========================/||*/
Comment

how to sort a 2D array in javascript

var 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']];

arr.sort(function(a,b) {
    return a[0]-b[0]
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript sort array by column 
Javascript :: multiple image upload react 
Javascript :: how to download an mp3 file in react native 
Javascript :: nestjs prisma on query 
Javascript :: javascript assign multiple variables to same value ES6 
Javascript :: faker js uuid example 
Javascript :: js promisify function 
Javascript :: count number of times an element is occuring in an array in javascript 
Javascript :: jquery table header agnostic of scroll 
Javascript :: jse api 
Javascript :: readmore jquery plugin 
Javascript :: webpack dev server 
Javascript :: elixir guards 
Javascript :: convert image url to base64 javascript without canvas 
Javascript :: data-toggle="tooltip not working due to jquery-ui.min.js 
Javascript :: animation end event angular 
Javascript :: exponential javascript 
Javascript :: The reduce() method executes a reducer function on each element of the array and returns a single output value. 
Javascript :: javascript nullish 
Javascript :: canvas setup 
Javascript :: 9 + 10 
Javascript :: how to use promise.all 
Javascript :: cy.contains 
Javascript :: @viewchild in angular :use for take any refrerence of element 
Javascript :: map function with params 
Javascript :: how to extract text from image using javascript 
Javascript :: slimscroll javascript 
Javascript :: random message in discord.js 
Javascript :: dayjs dayofyear 
Javascript :: sequelize date format 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =