How to shallow cloning an array of numbers in JavaScript

2 Answers

0 votes
array = [1, 2, 3, 4, 5, 6, 7];
clone = [].slice.call(array);

document.write(clone);

/*
run:
  
1,2,3,4,5,6,7
  
*/

 



answered Jul 24, 2017 by avibootz
0 votes
array = [1, 2, 3, 4, 5, 6, 7];
clone = Array.prototype.slice.call(array);

document.write(clone);

/*
run:
  
1,2,3,4,5,6,7
  
*/

 



answered Jul 24, 2017 by avibootz
...