I want to return value from nested function in javascript.
this is my code:
export const getArtistMusics = (id) => {
return cheerioInit(`https://mrtehran.com/artist/${id}`).then(($) => {
const SECTION = $('.musicbox-tracks .musicbox-item')
let musics = []
SECTION.each((i, elem) => {
return (async () => {
const PAGE_LINK = $(elem).attr('mtp-data-url')
return await getMusic(PAGE_LINK)
})()
})
return musics
})
}
as you see I returned an async IIFE function, but I don't know how to return the value (promise) outside of SECTION.each
block.
I want to push values to musics array and then return it.
What is the solution for this situation?