当前位置:网站首页>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
边栏推荐
- [jz46 translate numbers into strings]
- QT actual combat: Yunxi chat room
- 【工厂模式详解】工厂方法模式
- Leetcode167 - sum of two numbers II - double pointer - bisection - array - Search
- Raised exception class eaccexviolation with 'access violation at address 45efd5 in module error
- 在游戏世界组建一支AI团队,超参数的多智能体「大乱斗」开赛
- I/O复用的高级应用之一:非阻塞 connect———使用 select 实现(也可以用 poll 实现)
- Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
- 外包幹了四年,廢了...
- 每日一题-LeetCode396-旋转函数-递推
猜你喜欢
Thread synchronization, life cycle
eolink 如何助力远程办公
LeetCode162-寻找峰值-二分-数组
QT actual combat: Yunxi chat room
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
Comment eolink facilite le télétravail
How does eolink help telecommuting
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
Swift - Literal,字面量协议,基本数据类型、dictionary/array之间的转换
【无标题】
随机推荐
编程哲学——自动加载、依赖注入与控制反转
A good tool: aardio
剑指 Offer II 019. 最多删除一个字符得到回文(简单)
【无标题】
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
压缩映射定理
LeetCode151-颠倒字符串中的单词-字符串-模拟
I/O复用的高级应用:同时处理 TCP 和 UDP 服务
Do (local scope), initializer, memory conflict, swift pointer, inout, unsafepointer, unsafebitcast, success
go基础 反射
1 - first knowledge of go language
分享 20 个不容错过的 ES6 的技巧
Redis主从同步
Sword finger offer II 019 Delete at most one character to get palindrome (simple)
SQLSERVER事物与锁的问题
Unity_ Code mode add binding button click event
封面和标题中的关键词怎么写?做自媒体为什么视频没有播放量
The art of automation
Interviewer: let's talk about the process of class loading and the mechanism of class loading (parental delegation mechanism)
QT Detailed explanation of pro file