1. 确定一个字符串是否包含另一个字符串
1. indexOf
//以下三个方法都支持传入第二个参数表示开始搜索的位置
2. includes() 返回布尔值,表示是否找到了参数字符串
3. startsWith() 返回布尔值,表示参数字符串是否在原字符串的头部
4. endsWith() 返回布尔值,表示参数字符串是否在原字符串的尾部
2. repeat()
'x'.repeat(3) // 'xxx'
'hello'.repeat(2) //'hellohello'
3. padStart(), padEnd()
'x'.padStart(5, 'ab') //'ababx'
'x'.padEnd(5, 'ab') //'xabab'
可用于为数值补全指定位数
'1'.padStart(10, '0') // "0000000001"
4. trimStart(), trimEnd()
消除头部空格和消除尾部空格,返回新的字符串,不会改变原字符串
5. replaceAll() 替换所有
'123123123'.replaceAll('1', '5') // 523523523