1.用表示字符穿模板 例如 : let name = ”yangr“ let word = `woshi ${name}`; console.log(word); //将会输出 woshi yangr 2.
字符串模板可以随意换行,可以用于动态添加元素不用长的拼接字符串了。
3. includes() 方法
let aaa = “apple sdfdsfdsf”;
aaa.includes(“apple”); 返回false 或 true;
indexOf返回的是位置。
4. let str = “https://mp.csdn.net/mdeditor?not_checkout=1#”;
str.startsWith(“https”);
str.endsWith(".png");以什么结尾。
5.repeat 重复数据
let str = “牧马人 牧马人”;
console.log(str.repeat(1000)) //输出1000次
6.填充字符串
let str = “a”;
str.padStart(4,“xxx”); //4填充完的字符串的长度 结果为 xxxa
str.padEnd(4,“xxx”) // 结果为axxx
ecma6学习知识点(三)字符串模板及字符串新增
最新推荐文章于 2022-08-20 20:20:32 发布