Skip to content
Advertisement

Loop through array of objects and display them in react component

I have an array of object as follows. The data is based on created_date for e.g. (“2021-09-12”)

As you can see, i have got last 5 days of data. i.e. 12th Sep, 11th Sep, 10th Sep, 9th Sep and 8th Sep. The response does not have any data for 11th sept and 8th Sept.

JavaScript

Based on this above information, i have to display data in UI using react functional component as follows

JavaScript

Can someone please let me know how to achieve this. I tried the following but it doesnot display the correct data. I am not getting how to display correct project_id below its date. Also some dates have 2 project_ids in it. for e.g. Sep 09,2021 has 2 project_ids and both need to be displayed one below the other and then proceed with next date.

JavaScript

Advertisement

Answer

You can do something like this (see inline comments):

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement