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);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南