📜  String.toLower() js - Javascript (1)

📅  最后修改于: 2023-12-03 15:20:21.613000             🧑  作者: Mango

String.toLower() in JavaScript

The String.toLower() method is a built-in JavaScript function that converts the given string to lowercase and returns the resulting string. It does not modify the original string, but instead creates a new string with all the alphabetical characters converted to lowercase.

Syntax
string.toLower()
Return Value

The toLower() method returns a new string with all the alphabetical characters converted to lowercase.

Example
const str = "HELLO World";
const lowerStr = str.toLower();
console.log(lowerStr);  // Output: "hello world"

In the above example, the toLower() method is called on the str string, which converts all the uppercase letters to lowercase, resulting in the new string "hello world". The original string remains unchanged.

Notes
  • The toLower() method only converts alphabetical characters to lowercase. Non-alphabetical characters such as numbers and special characters are not affected.
  • If the given string is already in lowercase, the toLower() method returns the same string, as there is no conversion required.
Browser Support

The toLower() method is supported in all major browsers, including Chrome, Firefox, Safari, and Edge.

Note: It is important to note that the toLower() method is case-sensitive. If you want to perform a case-insensitive conversion, you can use the toLowerCase() method instead.

For more information, you can refer to the MDN web docs on String.toLower() method.