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);

 

相关文章

原文连接:https://www.cnblogs.com/dupd/p/5951311.htmlES6...
以为Es6,javascript第一次支持了module。ES6的模块化分为导...
视频讲解关于异步处理,ES5的回调使我们陷入地狱,ES6的Prom...
TypeScript什么是TypeScript?TypeScript是由微软开发的一款开...
export class AppComponent { title = 'Tour of heroes...
用 async/await 来处理异步昨天看了一篇vue的教程,作者用as...