Copy array - Node.js Array

Node.js examples for Array:Copy

Description

Copy array

Demo Code

Array.prototype.copy = function() {
    var copy = [];
    var len = this.length; // minor optimization
    for (var i = 0; i < len; i++) {
        if (this[i] instanceof Array) {
            copy[i] = this[i].copy();/*from  w w w  . ja  v a 2s  .  c o  m*/
        } else {
            copy[i] = this[i];
        }
    }
    return copy;
}

Related Tutorials