Skip to content

Instantly share code, notes, and snippets.

@haikelfazzani
Last active April 21, 2020 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haikelfazzani/6c6fb1e1cbe847b6ea796f3ae5d42c22 to your computer and use it in GitHub Desktop.
Save haikelfazzani/6c6fb1e1cbe847b6ea796f3ae5d42c22 to your computer and use it in GitHub Desktop.
javascript array map method for old browser
function map(a, cb) {
var res = [];
for (var i = 0, l = a.length; i < l; i++) {
res.push(cb(a[i], i, a));
}
return res;
};
// Example :
let r = map([1,2,3], function (value, index, array) {
return value*2;
})
console.log(r)
// [ 2, 4, 6 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment