js array array splicing push() concat() method efficiency comparison
I encountered this problem when I was working on the entry processing tool. When using concat()
splicing array, it takes 9 times push()
let words = []
let needToBeAddedArray = [] // 需要拼接到 words 的数组
Using concat()
takes 6081ms
words = words.concat(currentWords) // 拼接词组
push()
using 0616d1b8163ccd
words.push(...currentWords) // 拼接词组
Summarize
So array.push(...otherArray)
is the most efficient
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。