I want to combine same key element in below object and new array as output.
const items = [
{status:'all',task:'AA'},
{status:'all',task:'BB'},
{status:'working',task:'XX'},
{status:'working',task:'YY'},
{status:'complete',task:'ZZ'},
]
In items, I want to combine same status and make new array like below.
const newItems = [
{status:'all',task:['AA','BB']},
{status:'working',task:['XX','YY']},
{status:'complete',task:['ZZ']},
]
So I tried to make code below.
let baseItems = items
const newItems = baseItems.map((e)=>{
const newBaseItems = baseItems.filter((v)=>v.status === e.status)
newBaseItems.map((e)=>{
return {
status:e.status,
task:e.task
}
})
})
console.log(newItems)
but out was like [undefined,undefined,,,,] Does anyone teach me, please?
newBaseItemsin the first map