Get the App
SLTechnology News&Howtos  ›  Development  › 

How JavaScript capitalizes the first letter in a string

Shulou Source: shulou.com Published: 2022-06-01 05:03:42 10月01日 Update

This article mainly shows you "JavaScript how to capitalize the first letter in the string", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "JavaScript how to capitalize the first letter in the string" this article.

How to capitalize the first letter in a string

A very common operation is to capitalize the first letter of a string. Although many programming languages have a native way to do this, JS needs to do some work.

Let word = 'apply' word = word [0] .toUpperCase () + word.substr (1) console.log (word) / / "Apple"

Another way:

/ / This shows an alternative way let word = "apple"; / / use the extension operator (`...`) to split the characters const characters = [... word]; characters [0] = characters [0] .toUpperCase (); word = characters.join ("); console.log (word); / /" Apple "is all the content of the article" how to capitalize the first letter in a string ". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Characters capitals letters strings content articles methods learning help common easy to understand more organization knowledge editing programming languages industries languages information information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker vpn Shulou Technology NVidia