Javascript Array for(callback)

Description

Javascript Array for(callback)


Array.prototype.for = function(callback) {
    if(typeof callback !== "function") 
        return ;/*from ww w .j  a v  a  2  s  . com*/
    var len = this.length;
    for(var i = 0; i < len ; i ++) {
        callback(this[i]);
    }
}

var a = [1,2,3];

a.for(function(i) {
    console.log(i);
});



PreviousNext

Related