1.indexOf( ) 从左往右获取字符串的对应的索引号(并获取第一个字符的索引值)
let a = 'abcdefgc'
a.indexOf('c') // 2
2.lastIndexOf( ) 从右往左获取字符串的对应的索引号(并获取第一个找到的字符的索引值)
let a = 'abcdefgc'
console.log(a.lastIndexOf('c')) // 7
3.split("根据分割的字符") 分割字符串
let a = 'abcdefgc'
console.log(a.split("d")); //['abc', 'efgc']
console.log(a.split("")); //['a', 'b', 'c', 'd', 'e', 'f', 'g', 'c']
4.substring(开始位置,结束位置 ) 截取字符串
注意:第二个值可以省略,赋值时截取到此值位置,但不包含此处的字符串,返回值为截取后的结果
let a = 'abcdefgc'
console.log(a.substring(1, 5)); //bcde
5.substr(开始位置,截取长度 ) 截取字符串的
let a = 'abcdefgc'
console.log(a.substr(1, 3)); //bcd
6.toUpperCase( ) 转换成大写
let a = 'abcdefgc'
console.log(a.toUpperCase()); //ABCDEFGC
7.toLowerCase( ) 转换成小写
let a = 'abcdefgc'
console.log(a.toLowerCase()); //abcdefgc
8..startsWith('值') 检查是否以某个值开始 返回值为true,flase
let a = 'abcdefgc'
console.log(a.startsWith('a')); //true
9.endsWith('值') 检查是否以某个值结束 返回值为true,flase
let a = 'abcdefgc'
console.log(a.endsWith('a')); //false
10.replace('被替换的值','替换的值') 替换字符串
let a = 'abcdefgc'
console.log(a.replace('abcd', '12345')); //12345efgc
11.padStart(判断位数,'补的值') 判断字符串是否为指定的个数,不够在字符串开始位置补值
let a = 'abcdefgc'
console.log(a.padStart(11, '0')); // 000abcdefgc
12.padEnd(位数,值) 判断字符串是否为指定的个数,不够在字符串末尾位置补值
let a = 'abcdefgc'
console.log(a.padEnd(11, '0')); //abcdefg000