Nodejs Array Clone clone()

Here you can find the source of clone()

Method Source Code

var utils = {// www  .  java  2 s.  co m
   extend: function(orig, extra) {
      return Object.keys(extra).forEach(function(key) {
         orig[key] = extra[key];
      });
   }
};

Array.prototype.clone = function() {
   return this.slice(0);
};

module.exports = utils;

Related

  1. clone()
    Array.prototype.clone = function() {
      return this.slice(0);
    };
    
  2. clone()
    Array.prototype.clone = function() {
        return this.slice();  
    };
    
  3. clone()
    Array.prototype.clone = function () {
      var newArray = new Array();
      for(var index=0; index<this.length;index=index+1) {
        newArray[index] = this[index];
      return newArray;
    };
    
  4. 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;
    
  5. 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;
    
  6. 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);
    ...
    
  7. 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);