当前位置:网站首页>分享 20 个不容错过的 ES6 的技巧
分享 20 个不容错过的 ES6 的技巧
2022-04-23 14:49:00 【前端达人】
前言
大家好,我是 xieyezi,好久不见,我又重新回归掘金啦, 这次为大家整理了20个使用频率很高的ES6代码块,希望大家喜欢
文中代码对应的详细注释和具体使用方法都放在我的
github
上,源代码在底部连接
1. 打乱数组顺序

2. 去除数字之外的所有字符

3. 反转字符串或者单词

4. 将十进制转换为二进制或十六进制

5. 合并多个对象

6. ===
和 ==
的区别

7. 解构赋值

8. 交换变量的值

9-1. 判断回文字符串

回文字符串: 正着写和反着写都一样的字符串 (特别感谢\@浮生阁阁主[1]勘误)
9-2 判断两个字符串是否为互相排列

判断两个字符串是否为互相排列: 给定两个字符串,一个是否是另一个的排列
10. 可选链操作符

MDN: 可选链操作符(
?.
)允许读取位于连接对象链深处的属性的值,而不必明确验证链中的每个引用是否有效。?.
操作符的功能类似于.
链式操作符,不同之处在于,在引用为空(nullish ) (null
或者undefined
) 的情况下不会引起错误,该表达式短路返回值是undefined
。与函数调用一起使用时,如果给定的函数不存在,则返回undefined
例如:
if (res && res.data && res.data.success) {
//code
}
相当于:
if (res?.data?.success) {
// code
}
11. 三目运算符

12. 从数组中随机选择一个值

13. 冻结对象

14. 删除数组重复的元素

15. 保留指定位小数

16. 清空数组

17. 从 RGB
转换为 HEX

18. 从数组中获取最大值和最小值

19. 空值合并运算符

MDN: 空值合并操作符(
??
)是一个逻辑操作符,当左侧的操作数为null
或者undefined
时,返回其右侧操作数,否则返回左侧操作数。
20. 过滤数组中值为 false
的值

源码
20个不容错过的ES6技巧[2]
以上,码字作图很辛苦,还望不要吝啬手中的赞,你的点赞是我继续更新的最大动力!
关于本文
作者:Xieyezi
https://juejin.cn/post/7083145771461115941
版权声明
本文为[前端达人]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Ed7zgeE9X/article/details/124357649
边栏推荐
- ASEMI三相整流桥和单相整流桥的详细对比
- pnpm安装使用
- qt之.pro文件详解
- Mds55-16-asemi rectifier module mds55-16
- Role of asemi rectifier module mdq100-16 in intelligent switching power supply
- LeetCode165-比较版本号-双指针-字符串
- Frame synchronization implementation
- Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
- Leetcode153 - find the minimum value in the rotation sort array - array - binary search
- 1 - first knowledge of go language
猜你喜欢
全连接层的作用是什么?
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
Model location setting in GIS data processing -cesium
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
【NLP】HMM隐马尔可夫+维特比分词
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
线程同步、生命周期
Comment eolink facilite le télétravail
编程哲学——自动加载、依赖注入与控制反转
ArrayList collection basic usage
随机推荐
Explanation and example application of the principle of logistic regression in machine learning
What is the main purpose of PCIe X1 slot?
[proteus simulation] automatic range (range < 10V) switching digital voltmeter
你還不知道責任鏈模式的使用場景嗎?
[jz46 translate numbers into strings]
【JZ46 把数字翻译成字符串】
8.3 语言模型与数据集
QT Detailed explanation of pro file
1n5408-asemi rectifier diode
【工厂模式详解】工厂方法模式
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
One of the advanced applications of I / O reuse: non blocking connect -- implemented using select (or poll)
1-初识Go语言
A good tool: aardio
【Proteus仿真】自动量程(范围<10V)切换数字电压表
ArrayList collection basic usage
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
Epolloneshot event of epoll -- instance program
UML project example -- UML diagram description of tiktok