Home  >  Article  >  Web Front-end  >  How to convert letters to lowercase in javascript

How to convert letters to lowercase in javascript

青灯夜游
青灯夜游Original
2021-10-09 17:35:116955browse

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()

Example:

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

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()

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>

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!

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