localeCompare()
String
instance method getterS2C Home
« Globals « String « localeCompare()
Description
Returns a number dependant on the sort order of a string comparison.
- -1 if calling string comes before compared string.
- 0 if calling string same as compared string.
- 1 if calling string comes after compared string.
Syntax
Signature | Description |
---|---|
aString.localeCompare(compareString) | Returns a number dependant on the sort order of a string comparison. |
Parameters
Parameter | Description |
---|---|
compareString | The string to compare to. |
Examples
The code below compares two strings.
// Create two string variables.
var aString = 'acc';
var bString = 'abc';
/*
Compare strings (bstring is first in sort order).
/*
alert(aString.localeCompare(bString));
Related Tutorials
JavaScript Basic Tutorials - Lesson 8 - Strings