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