[Front-end | Code Optimization]——Part 1: List of common front-end code optimization points

1. Use 模板字符串 instead of string concatenation

Please add image description

2. Use 解构赋值to avoid repeated use of item.xx1, item.xx2

Please add image description

3. Determine whether an attribute in the array has a value.some()

Please add image description

4. includes()Used to determine whether an array contains an element - (can be used to avoid multiple repeated conditional statements)

Please add image description

5. Create a new array and array.form()replace it withfor循环 + push()

Please add image description

6. Use [ filter] + [ includes] to return the specified item instead of map+push

Please add image description

7. One of the differences between map and forEach is map可以返回新数组that you can use returnor ()to return

8. Determine and obtain duplicate items new Set + filter + indexOf- (can be used to prompt to mark duplicate item data)

Please add image description

Guess you like

Origin blog.csdn.net/sunshineTing2/article/details/132063513
Recommended