I am getting a very big object from my API Endpoint back. It is an object with multiple arrays. In each of them as an url (items.[0].images[0].url for example). I would like to create a new Array, just with the urls and store them in my Redux store.
I have tried to use a filter method, but I am getting back the same big Array every time, without any changes.
Furthermore, I notice if I console.log(typeof res.data.items) I am getting an object instead of an array as an output. I am a just confused, because my console is also saying res.data.items is an array.
Thats a part of my res object
{data: {…}, status: 200, statusText: "", headers: {…}, config: {…}, …}
config: {url: "/me/top/artists?limit=20&offset=11", method: "get", headers: {…}, baseURL: "https://api.spotify.com/v1", transformRequest: Array(1), …}
data:
href: "https://api.spotify.com/v1/me/top/artists?limit=20&offset=11"
items: Array(20)
0:
external_urls: {spotify: "https://open.spotify.com/artist/0fA0VVWsXO9YnASrzqfmYu"}
followers: {href: null, total: 4774667}
genres: (3) ["hip hop", "ohio hip hop", "rap"]
href: "https://api.spotify.com/v1/artists/0fA0VVWsXO9YnASrzqfmYu"
id: "0fA0VVWsXO9YnASrzqfmYu"
images: Array(3)
0:
height: 640
url: "https://i.scdn.co/image/4cb57ae1ef87546455db9cf65ba414c311ff459a"
1: {…}
2: {…}
....
that's my function
.then((res) => {
***let newdata = res.data.items.filter((url) => url.images[0].url)*** // not working
console.log('newdata', newdata) // getting back res.data.items
console.log(res.data.items) // Array
console.log('res', res)
console.log(typeof res.data.items) // Object ?
dispatch({
type: FETCH_TOP_25_ALBUMS,
payload: newdata,
})
})