the result as an array with the following sample data:
== sample data ==
const result = [
{"title": "example 1", "send_date": "26-08-2021", "total_push": "2"},
{"title": "example 1", "send_date": "21-08-2021", "total_push": "1"},
{"title": "example 1", "send_date": "21-08-2021", "total_push": "1"},
{"title": "example 1", "send_date": "20-08-2021", "total_push": "1"},
{"title": "example 1", "send_date": "20-08-2021", "total_push": "1"},
{"title": "example 1", "send_date": "20-08-2021", "total_push": "1"},
{"title": "example 1", "send_date": "20-08-2021", "total_push": "1"},
{"title": "example 1", "send_date": "20-08-2021", "total_push": "1"},
]
but i don't know why the function that i create return an empty array, am i doing it wrong?
function groupingData(arr) {
return arr.reduce((val, item) => {
val[item.send_date] = [...(val[item.send_date] || []), item];
return val;
}, []);
}
groupingData(result);
val is an array
Basically just change the [] at the bottom to {}
yup, i can get the result when i change the initValue to {} but i don't want it to be an object, i want an array instead.. i think i need to check the doc again :D
Can you show us an example result?
Обсуждают сегодня