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]
Written by Benjamin Cook
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#