I have an Object with a lot of keys. I need to convert this object to an array of objects but in such a way where I can still access the values for each object by the key.
I want to go from:
{'A': 123, 'B': 453, 'C': 4132}
To:
[{'A': 123}, {'B': 453}, {'C': 4132}]
I want to be able to access the values with a key such as 'A' or 'B' to return 123 and 453 respectively.
I am using Redux and currently my reducer looks like so:
const contextReducer = (state=null, action) => {
switch(action.type){
case 'CONTEXTUALIZE':
state = Object.values(action.payload)
state = state.filter(o => (o === state[0] || o === state[3]))
state = Object.assign(...state)
console.log(state)
return state
default:
return state
}
}
export default contextReducer
I have tried using Object.values(state) again right before the return but this gives me an array of items like so:
['A', 123, 'B', 453, 'C', 4132]