Array Join vs String Concat

前端 未结 7 1004
一向
一向 2020-11-29 03:14

Which method is faster?

Array Join:

var str_to_split = \"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z\";
var myarray = str_to         


        
7条回答
  •  情歌与酒
    2020-11-29 03:57

    According to this Google document titled 'Optimizing JavaScript code' string concat is slower then array join but apparently this is not true for modern Javascript engines.

    I made a benchmark for the Fibonacci test example that they used in the document and it shows that concatenating (gluing) the string is almost 4x as fast as using Array join.

提交回复
热议问题