当前位置:网站首页>Share 20 tips for ES6 that should not be missed
Share 20 tips for ES6 that should not be missed
2022-04-23 14:53:00 【Front end talent】
Preface
Hello everyone , I am a xieyezi, Long time no see , I'm back in the Nuggets again , This time, I sorted out 20 A high frequency of use ES6 Code block , Hope you enjoy it
The detailed comments and specific usage of the code are in my
github
On , The source code is connected at the bottom
1. Disorder array order

2. Remove all characters except numbers

3. Invert a string or word

4. Convert decimal to binary or hexadecimal

5. Merge multiple objects

6. ===
and ==
The difference between

7. Deconstruct assignment

8. Exchange the values of variables

9-1. Judge palindrome string

Palindrome string : Write the same string forward and reverse ( Special thanks \@ Floating garret master [1] Corrigendum )
9-2 Judge whether the two strings are arranged with each other

Judge whether the two strings are arranged with each other : Given two strings , Whether one is the arrangement of another
10. Optional chain operator

MDN: Optional chain The operator (
?.
) Allows you to read the value of an attribute deep in the chain of connected objects , Instead of explicitly verifying that each reference in the chain is valid .?.
The function of the operator is similar to.
Chain operators , The difference is , The reference is empty (nullish ) (null
perhapsundefined
) It doesn't cause errors , The short-circuit return value of this expression isundefined
. When used with function calls , If the given function does not exist , Then return toundefined
for example :
if (res && res.data && res.data.success) {
//code
}
amount to :
if (res?.data?.success) {
// code
}
11. Ternary operator

12. Randomly select a value from the array

13. Freeze objects

14. Delete duplicate elements of the array

15. Retention refers to the positioning of decimals

16. Empty array

17. from RGB
Convert to HEX

18. Get the maximum and minimum values from the array

19. Null merge operator

MDN: Null merge operator (
??
) It's a logical operator , When the operands on the left arenull
perhapsundefined
when , Returns its right-hand operand , Otherwise, return the left-hand operand .
20. The value in the filter array is false
Value

Source code
20 A must not miss ES6 skill [2]
above , Codeword mapping is hard , Please don't be stingy with your praise , Your praise is the biggest driving force for me to continue to update !
About this article
author :Xieyezi
https://juejin.cn/post/7083145771461115941
版权声明
本文为[Front end talent]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231449329431.html
边栏推荐
- Frame synchronization implementation
- Sword finger offer II 019 Delete at most one character to get palindrome (simple)
- We reference My97DatePicker to realize the use of time plug-in
- 1n5408-asemi rectifier diode
- Go basic reflection
- 压缩映射定理
- 脏读、不可重复读和幻读介绍
- 分享3个使用工具,在家剪辑5个作品挣了400多
- [stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
- Leetcode151 - invert words in string - String - simulation
猜你喜欢
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
1n5408-asemi rectifier diode
QT interface optimization: QT border removal and form rounding
Redis主从同步
Svn detailed use tutorial
[servlet] detailed explanation of servlet (use + principle)
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
Thread synchronization, life cycle
we引用My97DatePicker 实现时间插件使用
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
随机推荐
《JVM系列》 第七章 -- 字节码执行引擎
LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
分享3个使用工具,在家剪辑5个作品挣了400多
Alexnet model
we引用My97DatePicker 实现时间插件使用
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
[NLP] HMM hidden Markov + Viterbi word segmentation
【Proteus仿真】自动量程(范围<10V)切换数字电压表
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
epoll 的 ET,LT工作模式———实例程序
thinkphp5+数据大屏展示效果
LeetCode162-寻找峰值-二分-数组
Arduino for esp8266串口功能简介
Leetcode151 - invert words in string - String - simulation
Model location setting in GIS data processing -cesium
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
分布式事务Seata介绍
Explain TCP's three handshakes in detail
Achievements in science and Technology (21)
UML项目实例——抖音的UML图描述