当前位置:网站首页>分享 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
边栏推荐
- [proteus simulation] automatic range (range < 10V) switching digital voltmeter
- Unity_代码方式添加绑定按钮点击事件
- Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
- 【JZ46 把数字翻译成字符串】
- UML项目实例——抖音的UML图描述
- [NLP] HMM hidden Markov + Viterbi word segmentation
- Epolloneshot event of epoll -- instance program
- Pnpm installation and use
- Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
- MDS55-16-ASEMI整流模块MDS55-16
猜你喜欢
【无标题】
Introduction to Arduino for esp8266 serial port function
[detailed explanation of factory mode] factory method mode
MDS55-16-ASEMI整流模块MDS55-16
SVN详细使用教程
I thought I could lie down and enter Huawei, but I was confused when I received JD / didi / iqiyi offers one after another
A good tool: aardio
自动化的艺术
LeetCode162-寻找峰值-二分-数组
Progress in the treatment of depression
随机推荐
电容
Master in minutes --- ternary operator (ternary operator)
eolink 如何助力远程办公
Unity_ Code mode add binding button click event
Mq-2 and DS18B20 fire temperature smoke alarm system design, 51 single chip microcomputer, with simulation, C code, schematic diagram, PCB, etc
Bingbing learning notes: take you step by step to realize the sequence table
8.5 循环神经网络简洁实现
Leetcode151 - invert words in string - String - simulation
面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
Go basic reflection
中富金石财富班29800效果如何?与专业投资者同行让投资更简单
On the insecurity of using scanf in VS
Ali developed three sides, and the interviewer's set of combined punches made me confused on the spot
《JVM系列》 第七章 -- 字节码执行引擎
QT actual combat: Yunxi calendar
SQL中HAVING和WHERE的区别
How do I open the win10 startup folder?
一款不错的工具:aardio
牛客网数据库SQL实战详细剖析(26-30)
阿里研发三面,面试官一套组合拳让我当场懵逼