JavaScript String Methods 小教學 | 腦爸打有限公司

JavaScript String Methods 小教學


網頁設計、網站製作 專家!

Compbrother 腦爸打 @ 網頁設計、網站製作 小知識教學: JavaScript String Methods 小教學

文章發佈日期: 2021-12-06

小知識教學類型: 網頁設計、網站製作

前文我們提到,String字串在JavaScript程式語言當中,帶給了我們很多便利和功用性,當中有什麼現成的功能可用?

String字串長度檢測:
text(被定義String字串名稱).length;

slice(start position, end position): 輸入兩組數字,起始點和終點,String字串便會裁減成由起始點至終點的新字串。
let classmate = "Daniel, Peter, KiKi";
let peope_to_find = classmate.slice(8, 13);
最終peope_to_find的新字串便是Peter。

substring(start position, length): 類似於slice()的做法和用途,輸入兩組數字,起始點和起始點後的長度,String字串便會裁減成由起始點至起始點後的長度的新字串。
let classmate = "Daniel, Peter, KiKi";
let peope_to_find = classmate.substr(8, 5);
最終peope_to_find的新字串便是Peter。

replace(想被換的值, 目標的新值): 把String字串中的值轉換成其它值,輸入兩組字串,想被換的值和目標的新值。
let classmate = "Daniel, Peter, KiKi";
let peope_to_find = classmate.replace("Daniel", "Edith");
最終peope_to_find的新字串便是Edith, Peter, KiKi。

toUpperCase(): 把字串中的英文值變成大階
toLowerCase(): 把字串中的英文值變成細階
concat(): 可以把不同的字串連在一起
trim(): 把字串兩邊的空白值(whitespace)移除,這對於form表單輸入值的處理非常好用和常用!



如需協助 「網頁設計、網站製作」 ,歡迎立即 聯絡我們!



立即聯絡我們



Send a Message

Sed diam nonummy nibh euismod tincidunt ut laoreet dolore magnais.