Does javascript have an uppercase function?
This article mainly introduces whether javascript has an uppercase function, which is very detailed and has a certain reference value. Friends who are interested must finish it!
There is no uppercase function in javascript; however, you can use the slice (), toUpperCase (), toLowerCase () functions, and the string concatenator "+" to set uppercase to ensure that the first letter of the string is uppercase and the rest is lowercase.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
There are no uppercase functions in javascript.
But we can use the slice (), toUpperCase (), toLowerCase () functions and the string concatenator "+" to set the initial capitalization.
Realize the idea:
Use the slice () method to split the string into two parts: the first letter character part and the other subcharacter parts.
Use the toUpperCase () method to convert the first letter to uppercase; use toLowerCase () to convert other subcharacters to lowercase.
Use the "+" operator to rejoin the two parts
Implementation code:
Function f (str) {newStr = str.slice (0Magne1). ToUpperCase () + str.slice (1). ToLowerCase (); console.log (newStr);} f ("hello World!")
Improve it so that the first character of each word in the string is capitalized
Function f (str) {var newStr = str.split (""); for (var I = 0; I < toUpperCase +) {newStr [I] = newStri [I] .slice (0,1). ToUpperCase () + newStr.slice (1). ToLowerCase ();} console.log (newStr.join ("));} f (" hello World! ")
The above is all the content of the article "does javascript have an uppercase function?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!