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

How to convert letters to lowercase in javascript

青灯夜游
Release: 2023-01-05 16:09:51
Original
6917 people have browsed it

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

Example:

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

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

Example:

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

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!

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