Home >Web Front-end >JS Tutorial >How to convert string to uppercase in javascript
Conversion method: 1. Use toUpperCase() function, syntax "stringObject.toUpperCase()"; 2. Use toLocaleUpperCase() function, syntax "stringObject.toLocaleUpperCase()".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
1. Use the toUpperCase() function to convert a string to uppercase.
The toUpperCase() method is used to convert a string to uppercase.
Syntax
stringObject.toUpperCase()
Return value
A new string in which all lowercase characters of stringObject are converted to uppercase characters.
Example
<script type="text/javascript"> var str="Hello World!" document.write(str.toUpperCase()) </script>
Output:
HELLO WORLD!
2. Use the toLocaleUpperCase() function to convert the string to uppercase
## The #toLocaleUpperCase() method is used to convert a string to uppercase. SyntaxstringObject.toLocaleUpperCase()Return valueA new string in which all lowercase characters of stringObject are converted to uppercase characters. ExplanationDifferent from toUpperCase(), the toLocaleUpperCase() method converts the string to uppercase according to the local method. Only a few languages (such as Turkish) have local case mapping, so the return value of this method is usually the same as toUpperCase(). Example
<script type="text/javascript"> var str="Hello World!" document.write(str.toLocaleUpperCase()) </script>Output:
HELLO WORLD![Recommended learning:
javascript advanced 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!