includes():返回布尔值,判断是否找到参数字符串。(重点)
let string = "apple,banana,orange";
let a = string.includes("banana");
console(a);
startsWith():返回布尔值,判断参数字符串是否在原字符串的头部。
let b = string.startsWith("apple");
let c = string.endsWith("orange");
console.log(b);
console.log(c);
endsWith():返回布尔值,判断参数字符串是否在原字符串的尾部。
let d = string.startsWith("a",0)
console.log(d);
repeat(number):返回新的字符串,表示将字符串重复指定次数返回。
1.如果参数是小数,向下取整
2.如果参数是 0 至 -1 之间的小数,会进行取整运算,0 至 -1 之间的小数取整得到 -0 ,等同于 repeat 零次
3.如果参数是 NaN,等同于 repeat 零次
4.如果参数是负数或者 Infinity ,会报错:
5.如果传入的参数是字符串,零次
let str = "abc";
let a = str.repeat(3);
let a = str.repeat(-0.5);
let a = str.repeat(NaN);
let a = str.repeat(Infinity);
let a = str.repeat("hello");
console.log(str);
console.log(a);
padStart(总长度,“填充的字符串”):返回新的字符串,表示用参数字符串从头部(左侧)补全原字符串。
padEnd(总长度,“填充的字符串”):返回新的字符串,表示用参数字符串从尾部(右侧)补全原字符串。
以上两个方法接受两个参数,第一个参数是指定生成的字符串的最小长度,
第二个参数是用来补全的字符串。如果没有指定第二个参数,默认用空格填充。
let a = str.padStart(5,"x");
let b = str.padEnd(5,"y");
console.log(a);
console.log(b);
模板字符串`` 带值${a}
let a = 10;
let str = `abcdadhsasdasdh${a}
jsdh
jfdshjgsdfhjgsdfjd`
console.log(str);