Having a problem overriding the index of array in redux state :/
I am receiving a data from an endpoint and the results are:
e.g.
data:
[{
0: {id: 123, name: test1 },
1: {id: 456, name: test2 },
3: {id: 789, name: test3 },
}]
But I want to change the index of the array based on the result object.
data:
[{
123: {id: 123, name: test1 },
456: {id: 456, name: test2 },
789: {id: 789, name: test3 },
}]
Then save these to reducer.
This is the exact data that returned from an endpoint.
I have tried
let data = action.payload.data.map(item => {
return {
[item.id]: item
}
})
and got the result of
[
0: {123: {id: 123, name: 'test1'}},
1: {456: {id: 456, name: 'test2'}}
]
Any help is much appreciated!