Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #sort #string #array #javascript
ADD COMMENT
Topic
Name
4+9 =