js array数组拼接 push() concat() 的方法效率对比,差10倍
文章目录
js array数组拼接 push() concat() 的方法效率对比
在做词条处理工具的时候,遇到了这个问题,在使用 concat() 拼接数组的时候要比 push() 拼接耗时多9倍
let words = []
let needToBeAddedArray = [] // 需要拼接到 words 的数组使用 concat() 的耗时 6081ms
words = words.concat(currentWords) // 拼接词组
使用 push() 的耗时 56ms
words.push(...currentWords) // 拼接词组
总结
所以使用 array.push(...otherArray) 的方式是最高效的

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论