String.localeCompare
localeCompare — Compare two stings based on locale rules.
Description
String.localeCompare(string string, [string locales, [object options]])
Parameters
Name | Description | Type | Default | Optional |
---|---|---|---|---|
string | string | No | ||
locales | string | Yes | ||
options | See options below. | object | Yes |
Options parameter
The options parameter may contain one or more of the following data items.
- localeMatcher
Possible values are: "best fit" (default) or "lookup".
- usage
Possible values are: "sort" (default) or "search".
- sensitivity
Possible values are: "base", "accent", "case", or "variant" (default).
- ignorePunctuation
Possible values are: true or false (default).
- numeric
Possible values are: true or false (default).
- caseFirst
Possible values are: "upper", "lower" or "false" (default).
Return values
number primitive.
Examples
Example #1 – localeCompare example
In English the letter "å" comes before "z", while in Norwegian it comes after.
Equal compare will return a zero.