JSFiddle - React, Tailwind, and code Playground
by Dmitri Ganenco
JavaScript
const response = { // sample response for testing purpose
listOfObjects: [
{
id:'id1',
singleValue: 1
},
{
id:'id2',
singleValue: 2
},
{
id:'id3',
singleValue: 3
},
]
}
const mapped = response.listOfObjects.reduce(function(accumulator, currValue){
// here goes simple object transformation
let obj = {};
obj[currValue.id] = currValue.singleValue;
accumulator.push(obj);
return accumulator; // each iteration should retrun accumulator
}, []); // here you define starting object for your reduce method
console.log(mapped);