-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.

Tomiwa
  • 59
  • 7

1 Answers1

0

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

<ChartSongs key={data.key} audio={data?.hub?.actions?.[1]?.uri}/>
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80