How JavaScript capitalizes the first letter in a string
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!