Home > Web Front-end > JS Tutorial > body text

How to convert string to uppercase in javascript

青灯夜游
Release: 2021-10-08 17:22:50
Original
10648 people have browsed it

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()
Copy after login

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>
Copy after login

Output:

HELLO WORLD!
Copy after login
Copy after login

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()
Copy after login

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>
Copy after login

Output:


HELLO WORLD!
Copy after login
Copy after login
[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template