-1

I fetched data from an API and I get this : An array of arrays containing objects and properties containing the details of songs.

enter image description here

The issue is when i try to access the uri property, I get "Cannot read properties of undefined (reading '1')" with the code below :

 const songTitleEl = chartData.map(data =>(
    <ChartSongs key={data.key} audio={data?.hub?.actions[1]?.uri}/>
  ))

It should be working perfectly but it isn't and for the life of me I can't figure why.

0

1 Answer 1

0

actions could be null. Need the ? to check if index exists

<ChartSongs key={data.key} audio={data?.hub?.actions?.[1]?.uri}/>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.