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

How to convert letters to lowercase in javascript

青灯夜游
青灯夜游Original
2021-04-19 17:03:026852browse

How to convert javascript letters to lowercase: 1. Use toLowerCase() function, syntax "string.toLowerCase()"; 2. Use toLocaleLowerCase() function to convert strings according to the local host language environment is lowercase.

How to convert letters to lowercase in javascript

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

Method 1: Use toLowerCase() function

The toLowerCase() method is used to convert strings to lowercase. The syntax is as follows

string.toLowerCase()

Example:

var txt="HELLO WORLD!";
console.log(txt.toLowerCase());

Output:

How to convert letters to lowercase in javascript

Method 2: Use toLocaleLowerCase() function

toLocaleLowerCase() method converts a string to lowercase according to the locale of the local host. Local is determined based on the browser's language settings.

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.

Grammar:

string.toLocaleLowerCase()

Example:

var str="HELLO WORLD!";
console.log(txt.toLocaleLowerCase());

Output:

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