
正文
es6字符串扩展(+模板字符串拼接)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
includes()
判断字符串中是否包含指定的字串(有的话返回true,否则返回false)
console.log('hello world'.includes('world' , 7));//参数一:匹配的字串;参数二:从第几个开始匹配
startsWith() 判断字符串是否以特定的字串开始
endsWith() 判断字符串是否以特定的字串结束
let url = 'admin/index.php';console.log(url.startsWith('admin'));
//返回trueconsole.log(url.endsWith('php'));
//返回true
模板字符串拼接
原始的:
let tag = '<div><span>'+obj.username+'</span><span>'+obj.age+'</span><span>'+obj.gender+'</span></div>';console.log(tag);
高级的:
// 用反引号表示模板,模板中的内容可以有格式,通过${}方式填充数据
let fn = function(info){
return info;
}let tpl = `
<div>
<span>${obj.username}</span>
<span>${obj.age}</span>
<span>${obj.gender}</span>
<span>${1+1}</span>
<span>${fn('nihao')}</span>
</div>
`;console.log(tpl);

![[基础]ES6编程艺术 [基础]ES6编程艺术](https://www.04ip.com/template/qe/style/noimg/15.jpg)




