I have some difficulties accessing the key/values inside an object even tho i have said it is an array. (.map gave me error)
With axios post i have this type in response
type response = {
data: [];
};
Response from API:
"data": {
"thisoneineed": false,
"response": [{
"ID": "1234",
}],
"message": "this is a test message",
}
inside my components i get this from a redux state (i am saving it in the state after the response)
when i try this:
Object.entries(state).map(([key, value]) => {
console.log(key);
})
It gives me all they keys inside the array.
What i need to do is to access the value based on a key value so i did like this: (inside a component)
const insurance = useSelector(
(state: AppState) => state.session.data
);
Object.entries(insurance).map(([key, value]) => {
console.log(key[thisoneineed]);
})
This gives:
TS2304: Cannot find name 'thisoneineed'.
I was woundering how can i access the success key and get the value.
insurance.thisisoneineedinsuranceis an array or a JSON?anyis not a best practice, would suggest you to figureout the exact type and use it