Nodejs Array Duplicate duplicate()

Here you can find the source of duplicate()

Method Source Code

Array.prototype.duplicate = function() {
    return (this + ',' + this);
};

Related

  1. duplicate()
    Array.prototype.duplicate = function(){
      var newArr = this.slice();
      for(var i = 0; i < this.length; i ++){
        newArr.push(this[i]);
      return newArr;
    };
    console.log([1, 2, 3, 4].duplicate());
    
  2. duplicate()
    Array.prototype.duplicate = function(){
      return this.concat(this);
    duplicate([1,2,3,4,5])
    
  3. duplicate()
    function duplicateArray(arr) {
      return arr.concat(arr);
    Array.prototype.duplicate = function() {
      return this.concat(this);
    console.log([1,2,3,4,5].duplicate());
    console.log(duplicateArray([1,2,3,4,5]));
    
  4. duplicate()
    Array.prototype.duplicate = function(){
      var arrayVal = this;
      this.forEach(function(val){
        arrayVal.push(val);
      })
      return arrayVal;