/* Sort 2D array by column PASS: theArray (a 2D array), sortColumn(the column to sort by), sortAsString (if true, converts the value to a string before comparing) RETURNS: theArray, sorted by the column specified */ function sort2DArray (theArray, sortColumn, sortAsString = false) { theArray = theArray.sort(function(x,y){ if (sortAsString) { var xp = x[sortColumn].toString(); var yp = y[sortColumn].toString(); } else { var xp = x[sortColumn]; var yp = y[sortColumn]; } return xp == yp ? 0 : xp < yp ? -1 : 1; }); return theArray; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter