Javascript string case conversion method: 1. Use toLocaleLowerCase() or toLowerCase() to convert the string to lowercase; 2. Use toLocaleUpperCase() or toUpperCase() method to convert the string to uppercase.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
String defines 4 prototype methods to implement string case conversion operations. The description is shown in the table.
String method | Description |
---|---|
toLocaleLowerCase() | Convert the string to lowercase according to the local host’s locale Convert the string to uppercase |
toLowerCase() | Convert the string to lowercase |
toUpperCase() | Convert the string to uppercase |
The following code converts all strings to uppercase. | var s = "JavaScript"; console.log(s.toUpperCase()); //返回字符串“JAVASCRIPT” Copy after login | toLocaleLowerCase() and toLocaleUpperCase() are two localized prototype methods. They convert uppercase and lowercase letters natively, and since only a few languages (such as Turkish) have local-specific case mapping, they are usually the same as the return values of the toLowerCase() and toUpperCase() methods.
]
The above is the detailed content of How to convert string case in javascript. For more information, please follow other related articles on the PHP Chinese website!