Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Does javascript have an uppercase function?

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report