String.prototype.toLocaleUpperCase() - JavaScript 编辑
The toLocaleUpperCase()
method returns the calling string value converted to upper case, according to any locale-specific case mappings.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.Syntax
str.toLocaleUpperCase() str.toLocaleUpperCase(locale) str.toLocaleUpperCase([locale, locale, ...])
Parameters
locale
Optional- The
locale
parameter indicates the locale to be used to convert to upper case according to any locale-specific case mappings. If multiple locales are given in anArray
, the best available locale is used. The default locale is the host environment’s current locale.
Return value
A new string representing the calling string converted to upper case, according to any locale-specific case mappings.
Exceptions
- A
RangeError
("invalid language tag: xx_yy") is thrown if alocale
argument isn't a valid language tag. - A
TypeError
("invalid element in locales argument") is thrown if an array element isn't of type string.
Description
The toLocaleUpperCase()
method returns the value of the string converted to upper case according to any locale-specific case mappings. toLocaleUpperCase()
does not affect the value of the string itself. In most cases, this will produce the same result as toUpperCase()
, but for some locales, such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may be a different result.
Also notice that conversion is not necessarily a 1:1 character mapping, as some characters might result in two (or even more) characters when transformed to upper-case. Therefore the length of the result string can differ from the input length. This also implies that the conversion is not stable, so i.E. the following can return false
:x.toLocaleLowerCase() === x.toLocaleUpperCase().toLocaleLowerCase()
Examples
Using toLocaleUpperCase()
'alphabet'.toLocaleUpperCase(); // 'ALPHABET'
'Gesäß'.toLocaleUpperCase(); // 'GESÄSS'
'i\u0307'.toLocaleUpperCase('lt-LT'); // 'I'
let locales = ['lt', 'LT', 'lt-LT', 'lt-u-co-phonebk', 'lt-x-lietuva'];
'i\u0307'.toLocaleUpperCase(locales); // 'I'
Specifications
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论