1、indexOf() 可以用于判断是否存在,如果存在会显示当前位置,如果为-1则没有。也可以用于修改当前位置的值
let a='hello wored'
a.indexOf('he') //0
a.indexOf('as') //-1
2、incluces() 主要是判断是否存在,显示值为true或false
let a='hello wored'
a.includes('he') // true
a.includes('ae') // false
3、padStart(m,n) 用于在字符串的前面补充内容。m是一共显示多少位,n是位数不够在前面补充的内容
3.1、例如位数不够在前面补0
let a='hello wored'
a.padStart(18,'你好') // '你好你好你好你hello wored'
// 不满足2位前面补0
2.padStart(2,0)
4、padEnd(m,n) 用于在字符串的后面补充内容。m是一共显示多少位,n是位数不够在后面补充的内容
let a='hello word'
a.padEnd(18,'你好’) // 'hello wored 你好 你好 '
5、substr(index,length) 用于字符串的抽取 ,第一个参数为下标,第二个参数为长度
let a='hello wored'
a.substr(1,6) // 'ello w'
6、substring() 方法用于提取字符串中介于两个指定下标之间的字符
let str = "abcdefg";
str.substring(1,6); // 输出结果:"bcdef" [1,6)
str.substring(1); // 输出结果:"bcdefg" [1,str.length-1]
str.substring(); // 输出结果:"abcdefg" [0,str.length-1]
str.substring(6,1); // 输出结果 "bcdef" [1,6)
str.substring(-1); // 输出结果:"abcdefg"
7、replace() 用于替换字符
let a='hello wored'
a.replace('h','a') // 'aello wored'
a.replace(/o/g,'a') // 'hella wared'
8、split() 方法用于把一个字符串分割成字符串数组。该方法不会改变原始字符串
let a='h,l,l,o,e'
a.split(',') // [h,l,l,o,e]
9、slice() 方法用于截取 某段字符串,但不包含最后一位
let a='hello wored'
a.slice(0,2) // he
10、toLowerCase() 小写,toUpperCase() 大写
let a='hello wored'
a.toLowerCase() // 'hello wored'
a.toUpperCase() // 'HELLO WORED'