当前位置: 首页 > Web前端 > HTML

js array数组拼接 push() concat() 的方法效率对比,差10倍

时间:2023-03-28 14:54:26 HTML

js数组拼接push()concat()方法效率对比,相差10倍使用concat()拼接数组时,比push()拼接耗时多9倍letwords=[]letneedToBeAddedArray=[]//需要拼接成词的数组使用concat()耗时为6081mswords=words.concat(currentWords)//使用push()拼接词组耗时56mswords.push(...currentWords)//总结拼接短语,所以使用array.push(...otherArray)是最有效的方法