there are two different ways to copy a array, using Array.concat or Array.slice,
for example:
var a = [1, 2, 3],
c1 = [].concat(a),
c2 = a.slice(0);
which way is better?
For clarity, you should use the method that is the documented method of taking a copy of an array (or portion thereof):
var c2 = a.slice(0);
On any decent browser the performance difference will be negligible, so clarity should be the deciding factor.
In terms of performance, the difference between the two options are minimal, according to a jsperf.com test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With