I am trying to understand the use of locale parameter in String.prototype.localeCompare() method. The output for below two examples is the same for Spanish characters:
Without locale parameter: Code:
['único','árbol', 'cosas', 'fútbol'].sort(function (a, b) {
return a.localeCompare(b);
});
output:
["árbol", "cosas", "fútbol", "único"]
With locale parameter: Code:
['único','árbol', 'cosas', 'fútbol'].sort(function (a, b) {
return a.localeCompare(b, 'es');
});
output:
["árbol", "cosas", "fútbol", "único"]
From MDN localeCompare:
Optional. A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the locales argument, see the Intl page.
It seems that the locale parameter does not seem to have effect on the final output of localeCompare().
Please let me know of examples where using locale paramter produces a different result.