var str ="hello";
console.log(str.includes('h'));// true
console.log(str.includes('g'));// false
trim
从一个字符串的两端删除空白字符
无法删除单个字符与单个字符之间的空白字符
var str =' Nice Space hello';
console.log(str);
console.log(str.trim());/*
Nice Space hello
Nice Space
*/var strs ='A B';
console.log(strs);
console.log(strs.trim());/*
A B
A B
*/
repeat
repeat( number )
返回一个新字符串
该字符串包含被连接在一起的指定数量的字符串的副本。
相当于重复了多少遍原字符串。
var string ="Welcome ";
console.log(string.repeat(2));// Welcome Welcome
startsWidth
检查字符串是否以指定的字符串或字符开始。
返回 true / false
var str ="hello"
console.log(str.startsWith('h'));// true
console.log(str.startsWith('o'));// false
endsWith
检查字符串是否以指定的字符串或字符结束。
返回 true / false
var str ="hello"
console.log(str.endsWith('h'));// false
console.log(str.endsWith('o'));// true
concat
str.concat(str1,str2,…)
用于连接两个或多个字符串
此方法不改变现有的字符串
返回拼接后的新的字符串。
var str1 ='hello';var str2 =' world 'var str3 ='Bingo'
console.log(str1.concat(str2, str3));// hello world Bingo