日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

用JavaScript将字符串中的单词大写

發布時間:2025/3/11 javascript 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用JavaScript将字符串中的单词大写 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

String in JavaScript is a sequence of characters. And capitalizing characters of words in a JavaScript string will change each character of the string with the capital letter of it.

JavaScript中的字符串是字符序列。 而將JavaScript字符串中的單詞大寫會更改字符串中每個大寫字母的字符。

To convert words to uppercase we have the following method defined by slicing each character and then converting it to uppercase.

要將單詞轉換為大寫,我們可以通過對每個字符進行切片然后將其轉換為大寫來定義以下方法。

Components are defined as:

組件定義為:

Slice():
The slice method will return the specified element of the object and returns it to another object.

片():
slice方法將返回對象的指定元素,并將其返回到另一個對象。

For slice(3) for the array [3,5,6,8,9] will give 8.

對于數組[3,5,6,8,9]的slice(3)將得到8。

toUpperCase():
The method will return the uppercase changed the value of the character. For example: for 'f' input, the output is 'F'.

toUpperCase():
該方法將返回大寫更改的字符值。 例如:對于“ f”輸入,輸出為“ F”。

charAt():
returns the charter at the given index.

charAt():
返回給定索引的憲章。

Program to capitalize each character of the sting using JavaScript

程序使用JavaScript大寫字符串的每個字符

< script >function capitalizeEachWord(str) {var cstr = '';str.split('').forEach(function(char) {cstr = cstr + char.toUpperCase();});return cstr;}console.log("Hello, world!")var x = "learning JavaScript at include help"var y = capitalizeEachWord(x);console.log('x = ' + x);console.log('y = ' + y); </script>

Output

輸出量

Hello, world! learning JavaScript at include help LEARNING JAVASCRIPT AT INCLUDE HELP

翻譯自: https://www.includehelp.com/code-snippets/capitalize-words-in-a-string-in-javascript.aspx

總結

以上是生活随笔為你收集整理的用JavaScript将字符串中的单词大写的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。