当前位置:网站首页>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
边栏推荐
- LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
- Role of asemi rectifier module mdq100-16 in intelligent switching power supply
- Async void caused the program to crash
- I/O复用的高级应用:同时处理 TCP 和 UDP 服务
- 3、 Gradient descent solution θ
- QT interface optimization: QT border removal and form rounding
- ASEMI三相整流桥和单相整流桥的详细对比
- First acquaintance with STL
- Flink datastream type system typeinformation
- 面试官:说一下类加载的过程以及类加载的机制(双亲委派机制)
猜你喜欢
你还不知道责任链模式的使用场景吗?
Explanation and example application of the principle of logistic regression in machine learning
What is the effect of Zhongfu Jinshi wealth class 29800? Walk with professional investors to make investment easier
Svn detailed use tutorial
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
1n5408-asemi rectifier diode
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
A good tool: aardio
Leetcode149 - maximum number of points on a line - Math - hash table
1-初识Go语言
随机推荐
Vous ne connaissez pas encore les scénarios d'utilisation du modèle de chaîne de responsabilité?
【STC8G2K64S4】比较器介绍以及比较器掉电检测示例程序
Chapter 7 of JVM series -- bytecode execution engine
Leetcode165 compare version number double pointer string
SQL中HAVING和WHERE的区别
帧同步 实现
like和regexp差别
2-GO variable operation
Outsourcing for four years, abandoned
填充每个节点的下一个右侧节点指针 II [经典层次遍历 | 视为链表 ]
[untitled]
【无标题】
拼接hql时,新增字段没有出现在构造方法中
Redis主从同步
分布式事务Seata介绍
MySQL error packet out of order
分享3个使用工具,在家剪辑5个作品挣了400多
科技的成就(二十一)
do(Local scope)、初始化器、内存冲突、Swift指针、inout、unsafepointer、unsafeBitCast、successor、
自动化的艺术