×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Paul Zz
Added: Feb 20, 2017 5:34 PM
Modified: Feb 20, 2017 6:03 PM
Views: 11
Tags: array clone
ES6. Returns a clone array. Donor array remains unchanged.
  1. /**
  2.  * Returns new clone array
  3.  * @param {Array} arr
  4.  * @returns {Array|Boolean}
  5.  */
  6. function clone(arr) {
  7.     if (!(arr instanceof Array)) {
  8.         return false;
  9.     }
  10.     let res = [], len = arr.length;
  11.     for (let i = 0; i < len; i++) {
  12.         res[i] = arr[i];
  13.     }
  14.     return res;
  15. }