PDA

View Full Version : Sort 2D Arrray



locbtran
08-26-2011, 03:59 AM
I check the web and they only show you how to sort the whole array. I would like to be able to sort the subset of the 2D array. Here's my array.


var myArray=new Array(
new Array("af","ad","az","ab"),
new Array("bc","bd","bg","bb","bx"),
new Array("cf","ck","ca","cv","co"),
new Array("dd"));

How would I sort the sub array independently. So only the a's together, then only the b's together, etc.

thanks

jscheuer1
08-26-2011, 04:05 AM
You mean like:


var myArray=new Array(
new Array("af","ad","az","ab"),
new Array("bc","bd","bg","bb","bx"),
new Array("cf","ck","ca","cv","co"),
new Array("dd"));
for (var i = myArray.length - 1; i > -1; --i){
myArray[i].sort();
}
alert(myArray.join('\n'));

?