js array array splicing push() concat() method efficiency comparison, the difference is 10 times

KyleBing
中文

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) // 拼接词组

2021-10-18 14 46 27.jpg

push() using 0616d1b8163ccd

words.push(...currentWords) // 拼接词组

2021-10-18 14 43 03.jpg

Summarize

So array.push(...otherArray) is the most efficient

阅读 521

青枫ky
个人成长记录

前端,喜欢 Javascript scss,喜欢做一些实用的小工具

617 声望
13 粉丝
0 条评论

前端,喜欢 Javascript scss,喜欢做一些实用的小工具

617 声望
13 粉丝
文章目录
宣传栏