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

How to convert string to uppercase in javascript

青灯夜游
青灯夜游Original
2021-10-08 17:22:5010650browse

Conversion method: 1. Use toUpperCase() function, syntax "stringObject.toUpperCase()"; 2. Use toLocaleUpperCase() function, syntax "stringObject.toLocaleUpperCase()".

How to convert string to uppercase in javascript

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.

Syntax

stringObject.toLocaleUpperCase()

Return value

A new string in which all lowercase characters of stringObject are converted to uppercase characters.

Explanation

Different 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!

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