Other browsers may be int or maybe uint. Don’t worry about it. After all, we know the bottleneck is at 65535.
Based on the above foundation. You can consider using [].push.apply(a,b) instead of a=a.concat(b) when connecting arrays;
We just need to note that for safari, the length of b cannot exceed 65535.
The problem with
concat is that the new array generated traverses the two arrays a and b, and then puts the elements of a and b in sequence.
Test code:
var count = 100000, a = [1,2,3], b = [4,5,6], r = [], i, d;
d = new Date ;
for (i = count; i-- ;){
a.concat(b);
}
r[0] = new Date - d;
d = new Date ;
for (i = count; i-- ;){
r.push.apply(a,b );
//a = [1,2,3] ;
}
r[1] = new Date - d;
alert(r);
It can be concluded that even ancient browsers such as ie6 chrome2 safari 3 firefox 2 are completely victorious in push. Even if some browsers are removed //a = [1,2 ,3]; Comment part. The efficiency is actually better than concat. Such as chrome7 dev and safari 5.