[thelist] using array.sort() in JavaScript not handling case correctly

Kae Verens kverens at contactjuggling.org
Mon Mar 3 09:20:01 CST 2003


Tom Dell'Aringa wrote:
> Hello,
>
> I have a select list that I want to dynamically sort by alpha. I am
> able to get it to work using array.sort(), except for the fact that
> it places upper-case letters BEFORE lower-case letters. My script is
> simple enough, I loop through my listbox, pull each text/value array
> into a new array, use the sort() function then throw them back in.

Most sorts work using not the letter, but the ASCII value of the
character. IIRC, 'A' is 48, and 'a' is 96, so capitals naturally appear
before lowercases.

I suppose a method is to create a 2D array, the second dimension
containing both lower and standard versions of the words to be sorted.
You would then sort based on the lowercase version.

I don't have a snippet to show you, but I'm sure you could write up a
function easily that creates a 2D version from the 1D and then returns
the 1D version sorted correctly.

--
Kae Verens +----------------------------------+ webworks.ie
pay        |http://www.webworks.ie            |        bee
    play    |http://www.contactjuggling.org    |    boss
        kae |http://kverens.contactjuggling.org| god




More information about the thelist mailing list