- 檢索字符串出現的位置
'aba'.indexOf('a'); // 0, 從前面檢索'a'開始出現的位置
'aba'.lastIndexOf('a'); // 2, 從後面檢索'a'開始出現的位置
- 檢索匹配的字符串
'aba'.match('a'); // ["a"]
'aba'.match(/a/g); // ["a", "a"]
- 替換字符串
'aba'.replace('a', 1);
'aba'.replace(/(\w)/g, '$1,'); // "a,b,a,", (匹配內容), $1插入內容
- 分割成數組
'aba'.split('b'); // ["a", "a"], 匹配到的內容以逗號分隔成數組
'aba'.split(''); // ["a", "b", "a"]
'aba'.split('b', 1); // ["a"], 限制數組成員數
'aba'.split('a'); // ["", "b", ""], 匹配到的內容前或後沒字符串, 將以空字符串作爲數組成員
'aba'.split('c'); // ["aba"], 無匹配內容, 將整個字符串作爲一個數組成員
- 提取字符串
'aba'.substring(0, 2); // "ab", 提取位置[0, 2)的字符
'aba'.substr(1, 2); // "ba", 提取位置[1, ]後的2個元素
- 大小寫轉換
'aba'.toUpperCase(); // "ABA", 轉大寫
'aBa'.toLowerCase(); // "aba", 轉小寫