concat(str1,str2,···)
連接字串
indexOf(str,start)
返回 str 在字串中首次出現的位置
var str = "hello world"; str.indexOf("hello"); // 0 str.indexOf("o",5); // 7 str.indexOf("World"); // -1
lastIndexOf(str,start)
返回 str 在字串中最後出現的位置
var str = "hello world"; str.lastIndexOf("hello"); // 0 str.lastIndexOf("o",3); // -1 str.lastIndexOf("o",5); // 4
replace(regexp/substr,replacement)
在字串中用一些字元替換另一些字元,或替換一個與正則匹配的字串
var str = "I is Allen."; str.replace("is","am"); // "I am Allen."
slice(start,end)
返回字串的片段
var str = "I am Jack."; str.slice(3,7); // "m Ja" str.slice(3); // "m Jack." str.slice(3,-3); // "m Ja"
split(separator,limit)
將一個字串分割為子串,然後將結果作為字串數組返回
var str = "hello world"; str.split(" "); // ["hello","world"] str.split(" ",1); // ["hello"]
substr(start,lenght)
返回一個從指定位置開始的指定長度的字串
var str = "how do you do?"; str.substr(4,2); // "do" str.substr(4); // "do you do?" str.substr(4,0); // " " str.substr(4,-1); // " " str.substr(-3); // "do?"
substring(start,end)
返回位於 string 對象中指定位置的字串,包含 start 處字元,但不包含 end 處字元
var str = "how do you do?";str.substring(0,3); // "how"
toLowerCase()
把字串轉換為小寫
toUpperCase()
把字串轉換為大寫
var str = "How do you do?"; str.toLowerCase(); // "how do you do?" str.toUpperCase(); // "HOW DO YOU DO?"