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(...ar)
- 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