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) 的形式是最高效的