Home >Web Front-end >JS Tutorial >Performance comparison of three array copy methods in javascript_javascript skills
1. Three array copy methods
1. by slice
var arr = [1, 2, 3], copyArr;
copyArr = arr.slice();
2. by concat
var arr = [1, 2, 3], copyArr;
copyArr = arr.concat();
3 . by loop
var arr = [1, 2, 3], copyArr = [];
for (var i=0, j=arr.length; i
2. Test environment
Browsers: IE6, FF 3.5.5, Opera 10, Chrome 4.0.249, Safari 4.0.3
3. Test case
Use the above 3 methods to test an array with 500,000 items Carry out the copy operation, and then compare the time spent by the three methods.