Basically I have this data:
const arrayWithDates = [{2023-06-02: 2, 2023-06-21: 6},{
{2023-06-29: 2, 2023-06-23: 1}]
But I would like to transform the previous array to this:
Const arrayTransformed = [[{count:'2', date:'2023-06-02'}, {count:'6', date:'2023-06-21'}],[{count:'2', date:'2023-06-29'},{count:'1', date:'023-06-23'}]]
2
Answers
Assuming your dates in
arrayWithDates
are formatted as strings, this should work:You can map each record to an an array by converting the object to entries.
You will need to map each record’s key to a
date
field and the associated value to acount
field.Output
If you want to flatten the data, call
flat()
.Output