Nodejs Array Clone clone()

Here you can find the source of clone()

Method Source Code

Array.prototype.clone = function() {
    var isArr = function(elm){
        return String(elm.constructor).match(/array/i) ? true : false;
    }//from w  w w.  jav a2  s.  c  om
    var cloner = function(arr){
        var arr2 = arr.slice(0), len = arr2.length;
        for(var i=0; i < len; i++){
            if( isArr(arr2[i]) )
               arr2[i]=cloner( arr2[i] );
        }
        return arr2;
    }
    return cloner(this);
}

Related

  1. clone()
    var utils = {
      extend: function(orig, extra) {
        return Object.keys(extra).forEach(function(key) {
          orig[key] = extra[key];
        });
    };
    Array.prototype.clone = function() {
      return this.slice(0);
    ...
    
  2. clone()
    Array.prototype.clone = function() {
        var arr = this.slice(0);
        for( var i = 0; i < this.length; i++ ) {
            if( this[i].clone ) {
                arr[i] = this[i].clone();
        return arr;
    
  3. clone()
    Array.prototype.clone = function() {
        var arr = this.slice(0);
        for( var i = 0; i < this.length; i++ ) {
            if( this[i].clone ) {
                arr[i] = this[i].clone();
        return arr;
    
  4. clone()
    Array.prototype.clone = function() {
      var results = new Array(this.length);
      for (var i = 0, len = this.length; i < len; i++) {
        results[i] = this[i];
      return results;
    };
    Array.prototype.clone = function() {
      return [].concat(this);
    ...
    
  5. clone()
    Array.prototype.clone = function() {
        return [].concat(this);
    };
    function mySplit(str, ch) {
        var pos, start = 0, result = [];
        while ((pos = str.indexOf(ch, start)) != -1) {
            result.push(str.substring(start, pos));
            start = pos + 1;
        result.push(str.substr(start));
        return(result);    
    
  6. clone()
    Array.prototype.clone = function () {
        var cloneList = Array();
        for (var i = 0, a = 0; i < this.length; i++) {
            cloneList.add(this[i]);
        return cloneList;
    };
    
  7. clone()
    Array.prototype.clone = function() {
      var clone = new Array(this.length);
      for (var i = 0; i < this.length; i++) {
        clone[i] = this[i];
      return clone;
    };
    
  8. clone()
    Array.prototype.clone = function() {
        var newArr = new Array();
        for (var i = 0; i < this.length; ++i)
            newArr.push(this[i]);
        return newArr;
    
  9. clone()
    Array.prototype.clone = function()
      var copy = new Array(this.length);
      for (var i = 0; i < this.length; i++) {
        copy[i] = this[i];
      return copy;