Javascript method to convert string to uppercase: 1. Convert the string to uppercase through the "str.toUpperCase" method and return it; 2. Convert the string to uppercase according to the localization through the "str.toLocaleUpperCase" method A new string converted to uppercase by the mapping rule.
The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
JavaScript-Method to convert string to uppercase
str.toUpperCase()
str.toUpperCase() The method converts the string to uppercase and returns
var str = "Hello World Hello World"; var str2 = str.toUpperCase(); console.log(str2);//HELLO WORLD HELLO WORLD
str.toLocaleUpperCase()
str.toLocaleUpperCase() The method returns the string according to the localized case A new string converted to uppercase by the mapping rule.
toLocaleUpperCase() will not affect the value of the input string itself; in most cases, this method will produce the same value as toUpperCase(), but for some languages (locale), such as Turkish, because Their case mapping rules are different from Unicode's default mapping rules, so calling these two methods will produce different results
var str = "Hello World Hello World"; var str2 = str.toLocaleUpperCase(); console.log(str2);//HELLO WORLD HELLO WORLD
[Recommended learning: js basic tutorial]
The above is the detailed content of How to convert string to uppercase in javascript. For more information, please follow other related articles on the PHP Chinese website!