Skip to main content

Command Palette

Search for a command to run...

How to do Javascript object re-formatting

Published
1 min read
S

Software Engineer | #Blockchain developer | Blogger :)

<pre>I have data as follows:
{
   "2011":{
      "01":{
         "01":[
            {
               "date":"2011-01-01"
            },
            {
               "date":"2011-01-02"
            }
         ]
      },
      "02":{
         "01":[
            {

               "date":"2011-02-02"
            }
         ],
         "03":[
            {
               "date":"2011-02-15"
            },
            {                  
               "date":"2011-02-17"
            }
         ]
      }
   },
   "2012":{
      "01":{
         "01":[
            {
               "date":"2012-01-01"
            }
         ]
      },
      "03":{
         "01":[
            {
               "date":"2012-03-03"
            }
         ]
      }
   }
}
I need to construct final data in the below format:

[{year:2011,month:'Jan',week_no:1, week_total:2},
{year:2011,month:'Jan',week_no:2, week_total:2},
{year:2012,month:'Jan',week_no:1, week_total:1}
{year:2012,month:'Mar',week_no:1, week_total:1}]
Purpose is to obtain Year/Month / Week-wise totals. This data is required to plot some charts later. Help on this is highly appreciated..!..

##Article you may like:##

1.Extension to allow users to easily identify phishing attempts

2.Prefetching and dynamic routing with Next.js

3.Deep Dive into Page Lifecycle API

4.I’m Ready to check if the images or videos are loaded!

More from this blog

S

Shantun's Blog

30 posts

Software Engineer| #Blockchain developer | Blogger :) Connect with me on Twitter