Skip to content

Instantly share code, notes, and snippets.

@ozluy
Created September 9, 2019 14:02
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 ozluy/51017a252c70f1c79da2cb6537c4cfd3 to your computer and use it in GitHub Desktop.
Save ozluy/51017a252c70f1c79da2cb6537c4cfd3 to your computer and use it in GitHub Desktop.
Reducer JS
const myArr = [{numbers:[1, 2, 3]}, {numbers:[4, 5, 6]}, {numbers:[7, 8, 9]}];
/** Reducer array of objects to array of numbers */
const myNewArr = myArr.reduce(
(acc, curr) => [...acc, ...curr.numbers],
[] //initialState
)
console.log(myNewArr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment