Results 1 to 2 of 2

Thread: Sort 2D Arrray

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Sort 2D Arrray

    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:
    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You mean like:

    Code:
    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'));
    ?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •