当前位置:网站首页>分享 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
边栏推荐
- raised exception class EAccexxViolation with ‘Access violation at address 45EFD5 in module 出错
- 抑郁症治疗的进展
- Explain TCP's three handshakes in detail
- Resolve the conflict between computed attribute and input blur event
- The initial C language framework is suitable for review and preliminary understanding
- 解决computed属性与input的blur事件冲突问题
- Don't you know the usage scenario of the responsibility chain model?
- MDS55-16-ASEMI整流模块MDS55-16
- 1-初识Go语言
- Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
猜你喜欢
Programming philosophy - automatic loading, dependency injection and control inversion
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
DVWA之暴力破解(Brute Force)Low-->high
PCIe X1 插槽的主要用途是什么?
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
【Servlet】Servlet 详解(使用+原理)
你還不知道責任鏈模式的使用場景嗎?
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
随机推荐
QT interface optimization: double click effect
Progress in the treatment of depression
Explanation and example application of the principle of logistic regression in machine learning
外包幹了四年,廢了...
Advanced application of I / O multiplexing: Processing TCP and UDP services at the same time
牛客网数据库SQL实战详细剖析(26-30)
I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
On the insecurity of using scanf in VS
Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
PWM speed regulation control system of DC motor based on 51 single chip microcomputer (with complete set of data such as Proteus simulation + C program)
Matrix exchange row and column
MDS55-16-ASEMI整流模块MDS55-16
Set up an AI team in the game world and start the super parametric multi-agent "chaos fight"
多语言通信基础 06 go实现grpc的四种数据流模式实现
解决computed属性与input的blur事件冲突问题
三、梯度下降求解最小θ
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
eolink 如何助力远程办公
QT actual combat: Yunxi chat room
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、