Skip to content

Instantly share code, notes, and snippets.

@thomhos
Created October 17, 2016 09:31
Show Gist options
  • Save thomhos/2d13556a8dd6febccf8bb24ab9ba6373 to your computer and use it in GitHub Desktop.
Save thomhos/2d13556a8dd6febccf8bb24ab9ba6373 to your computer and use it in GitHub Desktop.
Array functions
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