1、includes()、startsWith()、endsWith()
- includes():返回布尔值,表示是否找到了参数字符串。
- startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
- endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。
第一个参数:字符;
第二个参数:表示开始搜索的位置;endsWith方法针对前n个字符,其他针对从第n个位置直到字符串结束。
2、repeat()
返回一个新字符串,表示将原字符串重复n次。
参数:
- 如果是小数,会向下取整;
- 如果为小于等于-1的负数或者Infinity,会报错;
- NaN等同于0;
- 字符串先转换呈数字。
var str = "hello world";
str.includes("h"); //true
str.startsWith("h");//true
str.endsWith("d");//true
str.startsWith("el", 1);//true 从位置1开始
str.endsWith("el", 3);//true 前3个字符包括
str.endsWith("el", 4);//false
str.endsWith("llo", 5);//true
str.endsWith("llo ", 6);//true
str.includes("wor",