This article organizes and shares ES6 tips, and compiled 20 frequently used ES6 code blocks for everyone. I hope you like it!
1. Disrupt the order of the array
##[Related recommendations:javascript learning tutorial】
2. Remove all characters except numbers
3. Reverse a string or word
4. Convert decimal to binary or hexadecimal
5. Merge multiple objects
6. ===<span style="font-size: 18px;"></span>
and ==<span style="font-size: 18px;"></span># The difference between
#7. Destructuring assignment
8. Exchange the value of the variable
9-1. Judgment Palindrome string
Palindrome string: A string that is the same when written frontward or backward9-2 Determine whether two strings are arranged with each other
Determine two characters Whether strings are permuted: Given two strings, whether one is a permutation of the other10. Optional chaining operator
MDN:Optional chainoperator ( ?. ) allows reading properties located deep in the connection object chain value without having to explicitly verify that each reference in the chain is valid. The function of the
For example:?.
operator is similar to the.
chain operator. The difference is that when the reference is null (nullish) (null
orundefined
) will not cause an error, the short-circuit return value of this expression isundefined
. When used with a function call, if the given function does not exist, returnsundefined
if (res && res.data && res.data.success) { //code} 复制代码
is equivalent to:
if (res?.data?.success) { // code}复制代码
11. Ternary operator
12. Randomly select a value from the array
13. Freezing Objects
14. Delete duplicate elements from the array
15. Keep the specified decimal places
##16. Clear the array
17. Convert from <span style="font-size: 18px;">RGB</span>
to <span style="font-size: 18px;">HEX</span>
18. Get the maximum and minimum values from the array
19. Null value coalescing operator
##MDN:Null value coalescing operator( ??
) is a logical operator. When the operand on the left is
nullor
undefined, it returns the operand on the right, otherwise it returns the left Operands.
20. Filter the values in the array that are false<span style="font-size: 18px;"></span>
Source code
https://github.com/xieyezi/vuepress-blog/ blob/master/docs/front-end/ES6-20 frequently used techniques.mdAbove, coding and drawing is very hard, I hope you don’t be stingy with your likes and likes. This is my biggest motivation to continue updating! [Related video tutorial recommendations:
web front-end]