I have an array of objects, each containing a date. My goal is to create a new array of objects grouped by weeks. Here is an example code snippet:
const data = [
{
"id": 1,
"status": 1,
"createdAt": "2022-05-01T08:28:36.284Z"
},
{
"id": 2,
"status": 2,
"createdAt": "2022-05-02T07:17:11.724Z"
},
{
"id": 3,
"status": 3,
"createdAt": "2022-05-10T07:03:44.465Z"
},
{
"id": 4,
"status": 3,
"createdAt": "2022-05-11T16:17:48.863Z"
}
]
The desired result is an array that groups objects by weeks as follows:
const newData = [
{
"week": 1,
"status": 1,
"status": 2
},
{
"week": 2,
"status": 3,
"status": 3
}]
Is this achievable? Can a property appear multiple times in the same object? Thank you