How to access values inside a multiple array JSON object?

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:
enter image description here

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?

2 thoughts on “How to access values inside a multiple array JSON object?”

  1. Your object data looks like an array of arrays of objects.

    This should work:

    data[0][0].symbol
    

    To log all the symbols of the first array:

    console.log(data[0].map(item => item.symbol))
    
    Reply
  2. 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

    data[0].map(item => console.log(item.symbol))
    
    Reply

Leave a Comment