Basically, the fastest one will depends on the browser like for Blink browser slice() is fastest, whereas for other browsers while loop is fastest. Also, you can use the below code to test in the browser console:
While Loop:
n = 1000*1000;
start = + new Date();
a = Array(n);
b = Array(n);
i = a.length;
while(i--) b[i] = a[i];
console.log(new Date() - start);
Slice :
n = 1000*1000;
start = + new Date();
a = Array(n);
b = a.slice();
console.log(new Date() - start);
I hope this will help.
Want to become a Java Expert? Join Java Certification now!!
Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java Programming: