In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to capitalize javascript". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Methods: 1, use the slice () method to separate the first character of the string; 2, use the toUpperCase () method to convert the first letter to uppercase; 3, use the toLowerCase () method to convert other characters to lowercase; 4, use the "+" operator to re-splice the two parts.
The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.
How to capitalize the first letter in javascript
In javascript, you can use the slice () method, toUpperCase () method, and toLowerCase () method to set the first letter uppercase to ensure that the first letter of the string is uppercase and the rest of the string is lowercase.
Steps:
● uses the slice () method to divide the string into two parts: the first letter character part and the other subcharacter parts.
● uses the toUpperCase () method to convert the first letter to uppercase and toLowerCase () to convert other subcharacters to lowercase.
● uses the "+" operator to rejoin the two parts
Example 1:
Function titleCase (str) {newStr = str.slice (0Magne1). ToUpperCase () + str.slice (1). ToLowerCase (); return newStr;} titleCase ("hello World!")
Output:
Hello world!
Example 2: make the first letter of each word in the string uppercase and the rest lowercase
Function titleCase (str) {var newStr = str.split (""); for (var I = 0; I
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.