I have the following data object. Each record contains order value and month of order. My objective here is to count how many orders per month have been ordered.
const data = [{
order: "a",
date: "Jan"
}, {
order: "b",
date: "Jan"
}, {
order: "c",
date: "Feb"
}]
So in the above code in Jan
there are two orders, one orders in Feb
and no orders for the rest of the months. So for the months which have no orders will have 0
value.
The expected output will be (array format)
orders = [{"Jan":2},
{"Feb":1},
{"Mar":0},
{"Apr":0},
{"Jun":0},
{"Jul":0},
{"Aug":0},
{"Sept":0},
{"Oct":0},
{"Nov":0},
{"Dec":0}]
Here is the CodeSandbox .