当前位置:网站首页>ES7/ES9 -- 新特性与正则
ES7/ES9 -- 新特性与正则
2022-06-25 21:50:00 【攀登程序猿】
ES7新特性
检查数组中是否包含某个元素 includes 2**10 2的10次方
let array = ['红楼梦','西游记','三国演义','水浒传']
console.log(array.includes('红楼梦')) // true
console.log(array.indexOf('红楼梦')) // 0
console.log(2**10) // 1024 2的10次方ES9 正则拓展
(1)正则分组
如下图所示,可以看到明显的正则分组,并且可以将匹配到的值重新命名,使用属性的方式去获取,防止了正则变化时,数字位置变化的问题
let str = '<a href="http://www.atguigu.com">尚硅谷</a>'
console.log(str)
const REG = /<a href="(?<url>.*)">(?<text>.*)<\/a>/ // 此处不能加单引号,?<name>是对匹配到的值进行重名名
let result = REG.exec(str)
console.log(result)
console.log(result.groups.url)
(2)反向断言与正向断言
添加条件,可以判断前面的是什么或者后面的是什么,防止匹配到多个

(3)dotAll
特点:.是元字符,除换行符以外的任意单个字符,ES9添加了/s可以匹配任意字符,在正则的最后添加一个/s即可
ES10 -- 对象拓展方法
对象和Map的互换

ES10 -- 字符串的trimStart()与trimEnd()
let str = ` ilove you
and you `;
console.log(str.trimStart()) //去除开始的空白
console.log(str.trimEnd()) // 去除末尾的空白ES10 -- flat与flatMap
flat可以把多维数组转换成一维数组,里面的数字是转换的深度

ES11 -- 私有属性
使用#标注私有属性即可,在类内部可以操作私有属性,在类外部是不可以的

ES11 -- String的mathAll 匹配所有
for (let v for result){
//批量提取
}
ES11 -- 可选链操作符?.
config&&config.db&&config.db.host,先判断config是否存在,然后判断config中的db是否存在,然后才获取的host,可以简写为config?.db?.host
ES11 -- 动态import
用的时候再导入,加载速度变快
btn.onclick = function () {
import('./m1.js').then(module => {
module.hello();
})
}ES11 -- BigInt类型 大整型,在数字后面加一个n即可
更大数字运算,它支持任意长度的整数,不能和普通数值进行运算,运算的结果都是BigInt
let n = 521n; let m = BigInt(521)
ES11 -- 绝对全局对象gloalThis,指向windows对象
边栏推荐
- NRM source switching tool
- Obsidian基础教程
- Nacos 源码分析01 代码结构
- Canoe: the fifth simulation project: simulation + test
- Online crudhasone Association query reports an error unabletouseinternalvariable:list
- 剖析虚幻渲染体系(16)- 图形驱动的秘密
- Hard liver! Super detailed basic introduction to Matplotlib!!!
- Analysis of China's tractor manufacturing and operation situation and forecast report of prospect trend 2022-2028
- Diagram of stack frame running process
- Reasons why MySQL cannot be connected externally after installing MySQL database on ECs and Solutions
猜你喜欢
Data annotation in the second half: growth flywheel under PLG mode Manfu Technology

【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧

Privatization lightweight continuous integration deployment scheme -- 03 deployment of Web services (Part 2)

Canoe: the fifth simulation project: simulation + test

Eureka core ⼼ source code analysis

2022-2028 global web and browser isolation platform industry research and trend analysis report

Zero Trust: break the passive development mode of "attack and defense" and build a "moat" for enterprise safety

面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?

Hard liver! Super detailed basic introduction to Matplotlib!!!

2022-2028 global SiC igniter industry research and trend analysis report
随机推荐
腾讯《和平精英》新版本将至:新增账号安全保护系统,游戏内违规行为检测升级
Yyds dry goods inventory CEPH installation visual dashboard
Some reflections on preparing for the Blue Bridge Cup
【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧
Flutter 網絡請求封裝之Dio(Cookie管理、添加攔截器、下載文件、异常處理、取消請求等)
China bed and mattress market status research analysis and development prospect forecast report (2022)
面对AI人才培养的“产学研”鸿沟,昇腾AI如何做厚产业人才黑土地?
Intimacy - [comfortable exit] - final communication to reduce injury
[WPF] XAML code skills that can be directly used for converting CAD engineering drawings to WPF
Unity技术手册 - 粒子基础主模块属性-上
Research and Analysis on the status quo of China's Cross lamp market and forecast report on its development prospect (2022)
2022-2028 global RBI platform industry research and trend analysis report
Ribbon core ⼼ source code analysis
Analysis report on demand and investment forecast of global and Chinese flame retardant hydraulic oil market from 2022 to 2028
Why absolute positioning overlaps
Jz-064- maximum value of sliding window
在线CRUDhasone关联查询报错Unabletouseinternalvariable:List
哪些PHP开源作品值得关注
Huasheng lithium battery IPO meeting: 9-month revenue of 690million; shenjinliang's family relationship is complex
Practice of product library platform nexus of Devops