How can I access array data inside my json object data
?
const [data, setData] = useState([])
const getData = () => {
axiosInstance
.get(url + slug)
.then(result => setData(result.data))
}
useEffect(() => {
getData()
}, [])
Here are something I’ve tried:
console.log(data['symbol'])
console.log(data[0]['symbol'])
console.log(data[0].symbol)
Here is the data being used in my state:
To keep it simple, lets say I want to the access first array, and console log all values for symbol
. How would I go about doing that?
Your object
data
looks like an array of arrays of objects.This should work:
To log all the symbols of the first array:
To access the first array you can use this
data[0]
to map through all the objects inside the first array and log them you do the following