es6字符串模板
// es5 let ananiah = "大诶呀"; let blog = "我要忘了你的样子"+ ananiah; console.log(blog); //我要忘了你的样子大诶呀 // es6字符串模板 let anania = "大诶呀"; let blogs = `<b>我要忘</b><br> 了你的样子${anania}`; document.write(blogs); //可以放HTML标签 let a = 1; let b = 2; let result = `${a+b}`; document.write(result); //3
字符串查找
// 字符串查找 //es5 let ananiahs = "大诶呀"; let blogss = "我要忘了你的样子大诶呀"; document.write(blogss.indexOf(ananiahs)); //8 //es6 let ananiahs6 = "大诶呀"; let blogss6 = "大诶呀我要忘了你的样子大诶呀"; document.write(blogss6.includes(ananiahs6)); //true 是否存在 document.write(blogss6.startsWith(ananiahs6)); //true 头部是否存在 document.write(blogss6.endsWith(ananiahs6)); //true 尾部是否存在
字符串复制
//字符串复制 repeat 方法 document.write('ananiah |'.repeat(30)); //复制三十个