Javascript Array copy()

Description

Javascript Array copy()


/**/*from   w w  w.  j  a  v a2  s  .c  o m*/
@Name: Array.prototype.copy
@Author: Paul Visco
@Version: 1.1 11/19/07
@Description: Makes a new independent copy of an array instead of a pointer to it
@Return: Array A new array with the same value as the one it is making a copy of
@Example:
var myNewArray = myArray.copy();
*/
Array.prototype.copy = function(){
  return this.filter(function(){return true;});
};

Javascript Array copy()

function shuffleArr(o) {
 for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
 return o;/*from   ww w.  j  a v a2 s  . c  om*/
}

Array.prototype.copy = function () {
 return JSON.parse(JSON.stringify(this));
}

Array.prototype.compare = function (array) {
    return JSON.stringify(this) === JSON.stringify(array);
}

Javascript Array copy()

Array.prototype.copy = function(){
 var tmp = [];/*  w w  w.j  a  va2s. c  o  m*/

 for (var i = 0; i < this.length; i++) tmp.push(this[i]);   

 return tmp;
}

Javascript Array copy()

View in separate window

/* Funktionen in anderen Bibliotheken
 * MakeArray(...) --> ZApi.Basic.Datatype.js
 *//*w w  w.  j ava  2  s  . c  o  m*/

Array.prototype.copy = function () {
return ((new Array()).concat(this));
}

//Ende des Verbergens vor nicht javascript f?gen Browsern --></script>
//</head>
//</html>

Javascript Array copy()

Array.prototype.copy = function() {
    var me = this;
    var newArray = [];
    var i;/*from w  ww  . j a v  a  2  s.c  o  m*/

    for (i = 0; i < me.length; i++) {
        newArray.push(me[i]);
    }

    return newArray;
};

Javascript Array copy()

Array.prototype.copy = function() {

  var rst = [];//from   w  w  w  .  j a v  a  2s . c  o m
  for (var i = 0; i < this.length; ++i)
    rst.push(this[i]);

  return rst;

}



PreviousNext

Related