I’m trying to access both keys and also values in an array of an API
export default const App= () =>{
const [data, setData] = useState([]);
console.log(data);
//Some fetch code here
//setData happen here
return (
<View >
<Text >fetched data</Text>
<Text>{data?.data?.a}</Text>
<Text>{data?.data?.b}</Text>
<Text>{data?.data?.c}</Text>
</View>
)
};
the supposed array is like this
arr = {code: 0, data:{a: 1, b: 2, c: 3}}
but it will only return 1, 2, 3 and I wanted it to be a: 1, b: 2, c: 3
2
Answers
You can access the Object.entries
Try this