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 :: Merger Douplicate array 
Javascript :: how to get perticular 5 string element out of 10 from array javascript 
Javascript :: Merger Douplicate array Object 
Javascript :: pg ssl settings js 
Javascript :: react strap documentation 
Javascript :: pass color json api 
Javascript :: enable clipboard 
Javascript :: Back button directive Angular 
Javascript :: chartJS Timeline with images 
Javascript :: textfield label language react 
Javascript :: fetch an webpage and parse js 
Javascript :: set popper click outside 
Javascript :: selectize get instance id from onchange 
Javascript :: safe check in js 
Javascript :: yarn dev error eacces windows 
Javascript :: Read data in props.histroy.push in react component 
Javascript :: 5.1.3. Boolean Expressions¶ 
Javascript :: express orm 
Javascript :: get nested value on object react using dot 
Javascript :: javascript function to print hello world 
Javascript :: get index after pushing value in array in js 
Javascript :: global require for current line 
Javascript :: check the constructor property to find out if an object is an Array (contains the word "Array"): 
Javascript :: Amazon Cognito domain on amplify not pulling 
Javascript :: undefined is not an object render header flatlist react hook 
Javascript :: Why get error 404 when I try to pass date variable in get request to web api 
Javascript :: Pignose Calender 
Javascript :: find duplicate characters from string in javascript 
Javascript :: javascript to python converter online 
Javascript :: regexp substr tester 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =