记住几个js的api并不能提交自己的竞争力,但可以提高开发效率。
includes() 判断字符串中是否含有其他字符串,返回布尔类型值
const name = 'hy';
const sentence = 'Hello hy! I am lq.';
const result = sentence.includes(name);
console.log(result);
复制代码
startsWith() 判断某个字符串是否在调用者的开头,返回布尔类型
sentence.startsWith('He');
复制代码
endsWith() 判断某个字符串是否在调用者的结尾,返回布尔类型
sentence.endsWith('lq.');
复制代码
replace()方法用来替换字符串中的子串
let name = 'repeat my name: liqi liqi liqi';
let result1 = name.replace('li', 'h');
console.log(name);
console.log(result1);
let result2 = name.replace(/li/g, 'h');
console.log(result2); 复制代码