String.trim( )
: 去掉字符串前后的空格
String.split( )
: 将字符串以某个字符分割,返回一个数组
1
2
3
4
多个分隔符
const list = "one,two;three"
const fruits = list.split(/[,;]/)
console.log(fruits); // ["one", "two", "three"]
String.indexOf( )
: 查找字符串是否包含某字符,存在返回一个索引大于等于
0, 否则返回-1
String.replace( )
: 替换字符串指定字符,
1
2
3
替换所有字符串的方法
"TESTS".replace(/S/g,"");
"TESTS".replaceAll(/S,"");