Using Map on a subarray in an array of Objects

Adebola's blog

I spent the last couple of hours trying to figure out how to get to the data in the Parts array within the Courses array of objects inside my react app and googled extensively without finding anything that could help.

I wanted to return the names of all the books within the parts array inside the courses array.

react1

Finally realized what I was doing wrong and figured that I needed to use two instances of the map function.

I will be using the following books array of objects to explain how I solved this problem.  We want to return only the categories of the books on the shelves.

react1

The first step is to call the map method on the outermost books array which contains our objects.

react1

The map method takes a callback function(a function within a function) and accepts a parameter to use in iterating through the array. We pass…

Ver la entrada original 83 palabras más