Home  >  Article  >  Web Front-end  >  How to convert string to uppercase in javascript

How to convert string to uppercase in javascript

藏色散人
藏色散人Original
2021-03-30 14:11:513755browse

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.

How to convert string to uppercase in javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn