-1

I am currently receiving data from Spotify via Search API. But, I don't know how to handle multiple objects.

Screenshot

I am currently, able to: response.data.albums.items and then map((item) => { });

Is there a way to render all of them, Albums, Artists, and Tracks?

Render to an <ul><li></li></ul>.

  • What do you mean with "But, I don't know how to handle multiple objects."? How do you want to handle it? – MWO Nov 10 '20 at 18:12
  • From the screenshot I posted: I get, **Albums**, **Artists**, and **Tracks**, and to render all of them at once in a **
    ** seems impossible, so I am able to only render one of them: *response.data.albums.items*.
    –  Nov 10 '20 at 18:14

1 Answers1

0

You can use Object.keys.

const keyArray = Object.keys(response.data);
const mergedArray = keyArray.map((key) => {
   console.log(response.data[key]); // Albums, Artists, Tracks
   return response.data[key].items; // I am assuming Albums,Artists and Tracks have items key.
});

console.log(mergedArray);
Md Sabbir Alam
  • 4,937
  • 3
  • 15
  • 30