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

How to convert letters to lowercase in javascript

青灯夜游
Release: 2021-10-09 17:35:11
Original
6997 people have browsed it

Javascript method to convert letters to lowercase: 1. Use toLowerCase(), the syntax "string.toLowerCase()"; 2. Use toLocaleLowerCase(), the syntax "string.toLocaleLowerCase()".

How to convert letters to lowercase in javascript

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

javascript converts letters to lowercase

Method 1: Use toLowerCase() method

The toLowerCase() method is used to convert a string to lowercase. The specific syntax format is as follows:

string.toLowerCase()
Copy after login

Example:

<script type="text/javascript">
console.log("A".toLowerCase());
console.log("B".toLowerCase());
console.log("C".toLowerCase());
</script>
Copy after login

Output result:

How to convert letters to lowercase in javascript

Method 2 : Use the toLocaleLowerCase() method

toLocaleLowerCase() method to convert the string to lowercase according to the local host's locale. The specific syntax format is as follows:

string.toLocaleLowerCase()
Copy after login

Generally, this method returns the same result as the toLowerCase() method. Only a few languages ​​(such as Turkish) have local-specific case mapping.

Note: The toLocaleLowerCase() method does not change the original string.

Example:

<script type="text/javascript">
document.write("P".toLocaleLowerCase());
document.write("H".toLocaleLowerCase());
document.write("P".toLocaleLowerCase());
</script>
Copy after login

Output result:

How to convert letters to lowercase in javascript

[Recommended learning: javascript advanced tutorial]

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