localeCompare : String comparisons : String JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » String » String comparisons »

 

localeCompare












localeCompare() helps sort string values

localeCompare() method takes the string to compare to.

localeCompare() returns one of three values:

If the String object comes alphabetically before the string argument, a negative number is returned.

If the String object is equal to the string argument, 0 is returned.

If the String object comes alphabetically after the string argument, a positive number is returned.








var oStringObject = new String("yellow");
alert(oStringObject.localeCompare("brick"));     //outputs "1"
alert(oStringObject.localeCompare("yellow"));    //outputs "0"
alert(oStringObject.localeCompare ("zoo"));     //outputs "-1"







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo String
» String comparisons