Created
October 17, 2016 09:31
-
-
Save thomhos/2d13556a8dd6febccf8bb24ab9ba6373 to your computer and use it in GitHub Desktop.
Array functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [1, 2, 3]; | |
// Reduce to object | |
const obj = arr.reduce((all, item, index) => { | |
// do something with item and all | |
all[index] = item; | |
// return all | |
return all; | |
}, {}); | |
// Map over arr | |
arr.map((item, index) => { | |
// do something with this item | |
functionCall(item); | |
}); | |
// Filter arr | |
const newArr = arr.filter((item) => (item > 2)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment