ES6---字符串

字符串模板
let name="yu"; let age=18; let=`我的名字叫${name},年龄:${age}`;

 字符串模板在拼装html内容时非常有用的   ,换行不需要用法做任务处理,可以随意的换行

 

2:字符串新增方法

2.1 字符串查找

2.1.1  includes包含

let str=" apple balala pear";

以前的方法

if(str.indexOf("apple")!=-1){

      console.log("包含apple")

}

现在新增的方法:

includes

str.includes("apple") 结果返回true或者false;

2.1.2 startsWith  以什么开头;

2.1.3 endsWith  以什么结尾;

2.1.4 填充在字符

  str.padStart("填充后整个字符串的长度","填充的内容");//往前填充;

  str.padEnd("填充后整个字符串的长度","填充的内容");//往后填充;

 

 

   

posted @ 2020-08-25 08:06  秋天的故事  阅读(62)  评论(0编辑  收藏  举报