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 @   _Origin  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示