I want to change this
const a = [{
id: 1,
name: 'a'
}, {
id: 2,
name: 'b'
}]
to
{
id: [1,2],
name: [a, b]
}
I'm stuck at how to push the id and name into the object
arr.reduce((accum, val) => {
let accum = {
id: val.id,
name: val.name
}
accum.id.push(val.id) //it doesn't work like this
return accum
}, {})