ECMAScript 6 入门之字符串
1、新增字符串的方法
1、字符是否存在
console.log("Yo".indexOf("Y")!=-1);
console.log("Yo".includes("Y"));
2、以哪个字符开头和结束
console.log("Yo".startsWith("Y"));
console.log("Yo".endsWith("o"));
3、重复多少次
console.log("Yo ".repeat(3));
2、模板字符串
let title="野外基地"; var tpl="div"+"<span>"+title+"</span>"+"</div>"; let tplw=` <div> <span>${title}</span> </div> ` console.log("tpl:",tpl); console.log("tplw:",tplw);
let title="野外基地"; let tplw=` <div> <span>${title+`<span>2016</span>`}</span> </div> ` console.log("tplw:",tplw);
let title="野外基地"; let tplw=` <div> <span>${title+`<span>${1234}2016</span>`}</span> </div> ` console.log("tplw:",tplw);