1. 字符串截取
slice(a, b):第一个参数代表开始位置,第二个参数代表结束位置的下一个位置
substring(a, b):第一个参数代表开始位置,第二个参数代表结束位置的下一个位置
substr(a, b):第一个参数代表开始位置,第二个参数代表截取的长度
2. 字符串去掉前几位
let str="abc12345";
console.log(str.slice(3)) // => 12345
console.log(str.substring(3)); // => 12345
console.log(str.substr(3)); // => 12345
3. 替换所有符合条件的字符串
'aabbcc'.replaceAll('b', '_') // => 'aa__cc'
4. 多个字符串替换
let str = '2021-05-20 08:00:00'
console.log(str.replace(/[- :]/g, '')) // => '20210520080000'
5. 多个字符串分割
let str = '2021-05-20 08:00:00'
console.log(str.split(/[- :]/g, '')) // => ['2021', '05', '20', '08', '00', '00']
6. 字符串拆分成数组
str.split(',') 字符串按逗号分割成数组
7. 字符串值在字符串中首次出现的位置
indexOf() 可返回某个指定的字符串值在字符串中首次出现的位置。如果要检索的字符串值没有出现,则该方法返回 -1。