当前位置:网站首页>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
边栏推荐
- 每日一题-LeetCode396-旋转函数-递推
- Go basic reflection
- Contraction mapping theorem
- Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
- [detailed explanation of factory mode] factory method mode
- GIS数据处理-cesium中模型位置设置
- LeetCode162-寻找峰值-二分-数组
- SQLSERVER事物与锁的问题
- A good tool: aardio
- Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
猜你喜欢
1 - first knowledge of go language
ASEMI三相整流桥和单相整流桥的详细对比
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
Model location setting in GIS data processing -cesium
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
Daily question - leetcode396 - rotation function - recursion
22年了你还不知道文件包含漏洞?
PCIe X1 插槽的主要用途是什么?
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
Mds55-16-asemi rectifier module mds55-16
随机推荐
脏读、不可重复读和幻读介绍
LeetCode167-两数之和II-双指针-二分-数组-查找
First acquaintance with STL
Is asemi ultrafast recovery diode interchangeable with Schottky diode
pnpm安装使用
QT Detailed explanation of pro file
The art of automation
每日一题-LeetCode396-旋转函数-递推
What is the main purpose of PCIe X1 slot?
ASEMI整流模块MDQ100-16在智能开关电源中的作用
UML学习_day2
【工厂模式详解】工厂方法模式
Svn detailed use tutorial
抑郁症治疗的进展
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
Swift: entry of program, swift calls OC@_ silgen_ Name, OC calls swift, dynamic, string, substring
Swift - literal, literal protocol, conversion between basic data types and dictionary / array
多语言通信基础 06 go实现grpc的四种数据流模式实现
LeetCode162-寻找峰值-二分-数组
How do I open the win10 startup folder?