js array数组拼接 push() concat() 的方法效率对比,差10倍
js array数组拼接 push() concat() 的方法效率对比
在做词条处理工具的时候,遇到了这个问题,在使用 concat()
拼接数组的时候要比 push()
拼接耗时多9倍
let words = []
let needToBeAddedArray = [] // 需要拼接到 words 的数组
使用
concat()
的耗时 6081mswords = words.concat(currentWords) // 拼接词组
文章图片
使用
push()
的耗时 56mswords.push(...currentWords) // 拼接词组
文章图片
总结 【js array数组拼接 push() concat() 的方法效率对比,差10倍】所以使用
array.push(...otherArray)
的方式是最高效的推荐阅读
- 数组常用方法一
- Java|Java基础——数组
- 字符串拼接成段落,换行符(\n)如何只执行n-1次
- JS常见数组操作补充
- JS|JS 数组求和与数组求平均值
- 超帅的js数组去重
- JavaScript|JavaScript — 初识数组、数组字面量和方法、forEach、数组的遍历
- JavaScript判断数组的方法总结与推荐
- 一些非常有用的snippets
- [leetcode数组系列]1两数之和