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

How to convert lowercase letters to uppercase in javascript

青灯夜游
青灯夜游Original
2021-11-26 17:18:2242179browse

JS method to convert lowercase letters to uppercase: 1. Use toUpperCase() function, syntax "string.toUpperCase()"; 2. Use toLocaleUpperCase() function, syntax "string.toLocaleUpperCase()".

How to convert lowercase letters to uppercase in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript method to convert lowercase letters to uppercase

Method 1: Use toUpperCase()

toUpperCase() method is used to convert strings to uppercase.

Syntax:

string.toUpperCase()

Return value: a new string in which all lowercase characters of string are converted to uppercase characters.

var str="Hello World!"
document.write(str.toUpperCase())

How to convert lowercase letters to uppercase in javascript

Method 2: Use toLocaleUpperCase()

toLocaleUpperCase() method is used to convert strings to uppercase.

Syntax:

string.toLocaleUpperCase()

Return value: a new string in which all lowercase characters of string are converted to uppercase characters.

Note: 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().

var str="Hello World!"
console.log(str.toLocaleUpperCase());

How to convert lowercase letters to uppercase in javascript

【Related recommendations: javascript learning tutorial

The above is the detailed content of How to convert lowercase letters 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