Look at the notes, I hope it can be written in one sentence, is there such a simple way of writing?
const t = [ {name: 'John', value: 111}, {name: 'Mary', value: 222}];const param = t.reduce((p, n) => { // Can it be written in one line here, similar to this t.map(k => k.child); p[n.name] = n.value; return p;}, {})
const t = [ {name: 'John', value: 111}, {name: 'Mary', value: 222}];const param = t.reduce((p, n) => (p[n.name] = n.value,p), {})
Coincidentally, I thought about this issue recently
t.reduce((p, n) => ({...p, [n.name]: n.value}), {})
const t = [ { name: 'John', value: 111 }, { name: 'Mary', value: 222 }];const param = t.reduce((p, n) => ({ ...p, [n.name]: n.value }), {})
0 Comments