大家好,又见面了,我是你们的朋友全栈君。
const name = 'hy';
const sentence = 'Hello hy! I am lq.';
const result = sentence.includes(name);
console.log(result); // true
复制代码
sentence.startsWith('He'); // true
复制代码
sentence.endsWith('lq.'); // true
复制代码
let name = 'repeat my name: liqi liqi liqi';
let result1 = name.replace('li', 'h');
console.log(name); // 'repeat my name: liqi liqi liqi'
console.log(result1); // 'repeat my name: hqi liqi liqi';
let result2 = name.replace(/li/g, 'h');
console.log(result2); // 'repeat my name: hqi hqi hqi';复制代码
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106851.html原文链接:https://javaforall.cn