According to the documentation, Javascript doesn't have associative arrays. See http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/array.html for reference.

But then what exactly is document.forms["myForm"].elements["formElement"]? I suppose they might be custom collections, but they're not even mentioned in my copy of the Javascript Bible (admittedly it's pretty old).

Assuming you can actually make an associative array (for which I can't find a constructor in the documentation mentioned above) and you want to sort by name, you'd have to write your own function to do it, which isn't difficult.

Here's a function skeleton for you to fill in the blanks:

function SortArrayByKey(array)
{
    // extract all the keys into a separate array

    // sort the array of keys

    // create a new empty array the same size as your original array

    // loop through the array of sorted keys

// at each index of the sorted loop, assign the value of the original array with the current key to the new array
}


Amrit Hallan wrote:

How do we sort an associate array such as
var name=new Array();
name["name1"]="City1";
name["name2"]="City2";

How do we sort this array by names?

Thanks
Amrit
http://www.bytesworth.com



____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED] Send Your Posts To: [EMAIL PROTECTED]
To set a personal password send an email to [EMAIL PROTECTED] with the words: "set WDVLTALK pw=yourpassword" in the body of the email.
To change subscription settings to the wdvltalk digest version:
http://wdvl.internet.com/WDVL/Forum/#sub


________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.



-- :::::::::::::::::::::::::::::: Howard Cheng http://www.howcheng.com/ Wise-cracking quote goes here.

____ • The WDVL Discussion List from WDVL.COM • ____
To Join wdvltalk, Send An Email To: mailto:[EMAIL PROTECTED]
      Send Your Posts To: [EMAIL PROTECTED]
To set a personal password send an email to [EMAIL PROTECTED] with the words: "set WDVLTALK 
pw=yourpassword" in the body of the email.
To change subscription settings to the wdvltalk digest version:
   http://wdvl.internet.com/WDVL/Forum/#sub

________________  http://www.wdvl.com  _______________________

You are currently subscribed to wdvltalk as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

To unsubscribe via postal mail, please contact us at:
Jupitermedia Corp.
Attn: Discussion List Management
475 Park Avenue South
New York, NY 10016

Please include the email address which you have been contacted with.



Reply via email to