Skip to content

Instantly share code, notes, and snippets.

@zwacky
Last active January 20, 2016 15:13
Show Gist options
  • Save zwacky/4483216adc239c0f10c1 to your computer and use it in GitHub Desktop.
Save zwacky/4483216adc239c0f10c1 to your computer and use it in GitHub Desktop.
ES6 spread to the rescue
// get all items of all players
/* WITHOUT ES6 spread operator */
const items = [];
players.forEach((player) => {
player.forEach((item) => {
items.push(item);
});
});
/* WITH ES6 spread operator */
const items = players.reduce((items, player) => […items, …player.items], []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment