我在Javascript中有一个数组,如果它们具有相同的remind.date,我需要组合对象
const tasks = [
{
id: 1,
title: "call Tom",
reminders: {
date: "2022-02-01",
time: "09:30"
}
},
{
id: 2,
title: "Meet Bred",
reminders: {
date: "2022-02-01",
time: "10:30"
}
},
{
id: 3,
title: "Mail Susan",
reminders: {
date: "2022-03-01",
time: "19:00"
}
},
输出应该是这样的
const combinedTasks = [
{
id: 1,
tasks: ["call Tom", "Meet Bred"],
reminders: {
date: "2022-02-01",
time: "09:30"
}
},
{
id: 3,
tasks: ["Mail Susan"]
reminders: {
date: "2022-03-01",
time: "19:00"
}
}
我想我需要使用 Array.reduce 方法,但我不知道如何正确地做到这一点