Last Updated: February 25, 2016
·
922
· benjycook

Map method for Arrays in javascript

Array.prototype.map = function(func) {
    for(var i = 0; i<this.length;i++) {
        this[i] = func(this[i]);
    }
    return this;
}

Usage example:

a = [1,2,3];
a.map(function(x) {
    return x*2;
})

a is now [2,3,4]