Performing some data conversion exercises and getting stuck. I have an object that I want to convert to look like the output from (starting) β to (expected ending) , described below. I am trying to use Array.reduce and Object.assign to keep the output clean. but I just can't get it to work correctly.
const starting = {topic: {id: 2}, products: {id: 3}}; const ending = Object.keys(starting).reduce((p, key) => { if(!p[key]) p[key] = key; return Object.assign(p[key], starting[key].id); }, {})
javascript arrays reduce transformation
Matthew harwood
source share