Skip to content
Advertisement

I want to make custom array of object based on my result [closed]

Basically i know array, and it’s prototype methods, I tried to get the result by using new Set(), map and filter. but somehow i stuck at some point to get the desired result.

Below are the details about the problem and how i want the result.

Result I’m Getting

JavaScript

I want to convert this result like below, NOTE : Based on Date.

JavaScript

THANK YOU FOR YOUR CONTRIBUTION

Advertisement

Answer

You could make it dynamic for any number of status.

  • Create a Set of status to get all the unique status
  • Create a partial object with all status as key and 0 as their value. There are many ways to create it. I’m using Object.fromEntries. It will look like this: { "incomplete": 0, "Complete": 0 }
  • Loop through the array. Use a group object with each Date as the key and object needed in the output as its value.

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