240
世界上有2种人,一种懂二进制,另一种不懂二进制。

ES6-字符串扩展

1】几个新的API

includes() : 返回布尔值,表示是否找到了参数字符串

startWith(): 返回布尔值,表示参数字符串是否在原字符串的头部

endsWith() : 返回布尔值,表示参数字符串是否在原字符串的尾部
   let str = "hello.vue";
   console.log(str.startsWith("hello"));//true
   console.log(str.endsWith(".vue"));//true
   console.log(str.includes("e"));//true
   console.log(str.includes("hello"));//true


   let str = "hello.vue";
   console.log(str.startsWith("hello"));//true
   console.log(str.endsWith(".vue"));//true
   console.log(str.includes("e"));//true
   console.log(str.includes("hello"));//true

 

 

 

2】字符串模板

//1、大段字符串不用想以前那样拼接
    let ss = `<div>
          <span>hello world<span>
        </div>`;
    console.log(ss);

 

 

 //2、字符串插入变量和表达式,变量名写在 ${} 中,${} 中可以放入 JavaScript 表达式。
    function fun() {
      return "这是一个函数"
    }
    //其中abc是前面获得person的name值变量
    let info = `我是${abc},今年${age + 10}了, 我想说: ${fun()}`;
    console.log(info);

 

posted @ 2022-07-08 13:55  _Origin  阅读(26)  评论(0)    收藏  举报