Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Javascript Map, Filter, Reduce Usage
var a = [1,2,3,4,5];
//MAP
var mapped = a.map(function(number) {
return number * 2;
});
console.log(mapped);
//FILTER
var filtered = a.filter(function(number) {
return number % 2;
});
console.log(filtered);
//REDUCE
var reduced = a.reduce(function(prevNumber, currentNumber) {
return prevNumber + currentNumber;
});
console.log(reduced);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.