Skip to content

Instantly share code, notes, and snippets.



Created Feb 4, 2019
What would you like to do?


1. Show Array

  • Let's pretend for a second that this pplFromAPI array isn't hardcoded, and instead it's being returned to us depending on service calls elsewhere in our application.
  • It's our job to transform this data into a 1dimensional array for the UI to iterate over and display accordingly.

2. - const flattenData = (arr = peopleArray) => [].concat(

  • One way of implementing this is using .concat in conjunction with the ...spread operator introduced with the release of ES6.

3 "highligh dots"

Shields us having to iterate thru each nested array, building up the final value on each pass.

4. Inspect result

  • We see that var name holds all of our data in one array. In other words, our array has been flattened.
  • Upon checking the requirements however o we realized that several of the endpoints return the string value inside of arrays. --->

5. paste nested array

  • And if we look at the result from render data we see all of these nested arrays are still present.
  • This logic would involve us checking for nested arrays of the array and unbox anź however the
  • .flat method

oour function to work recu to the flat method joining the array.prototype family

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.