It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Sort 2D Arrray

Sort 2D Arrray

Postby hiyatran on Fri Aug 26, 2011 3:49 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.

Code: Select all
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
hiyatran
 
Posts: 18
Joined: Mon Jun 21, 2010 1:53 am

Re: Sort 2D Arrray

Postby hj5612 on Tue Sep 06, 2011 1:00 pm

<script type="text/javascript">
<!--
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"));

/*myArray.sort();
document.write(myArray);*/


/*
for(i=0; i<myArray.length; i++) {
myArray[i].sort();
document.write(myArray[i]);
document.write("<br>");

}
*/

i = myArray.length;
j=0;
do
{
myArray[j].sort();
document.write(myArray[j]);
document.write("<br>"); // new line
j++;
}
while (i>j);


//-->
</script>
hj5612
 
Posts: 1
Joined: Tue Sep 06, 2011 12:47 pm


Who is online

Users browsing this forum: No registered users and 7 guests