English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
localeCompare()The method compares two strings in the current language environment.
This method returns a number that indicates whether the string is located before, after, or equal to compareString in the sorting order.
string.localeCompare(compareString)
var a = 'AB'; var b = 'CD'; var c = a.localeCompare(b);Test and see‹/›
All browsers fully support the localeCompare() method:
Method | |||||
localeCompare() | is | is | is | is | is |
Parameter | Description |
---|---|
compareString | The string compared with the reference string |
Return value: | a number indicating whether the reference string is in the sorting ordercompareStringbefore, after, orwithIdentical. return one of the following values:
|
---|---|
JavaScript Version: | ECMAScript 1 |