This discussion thread delves into the intricacies of sync versus async operations and offers potential solutions. However, despite implementing one of the suggested solutions, I continue to encounter errors.
I believe I have reached my limit in understanding ES
here, and I am in dire need of assistance as I cannot comprehend why this issue persists. Below is the code snippet from my nuxt
project, which I migrated from a backend built on express
.
async fetch({store, error}) {
let series = '', courses = [], album = {}
store.state.courses.forEach(async course => {
album = {...course}
series = course.uri.split('/')[2]
try {
const {data: {data}} = await axios.get('http://localhost:3000/luvlyapi/videos', {
params: {
series //? album id
}
})
album['videos'] = data
courses.push(album)
console.log('loop', courses)
} catch (err) {
error({statusCode: err.statusCode, message: err})
}
})
console.log({courses})
store.commit('SET_COURSES', courses)
} https://i.sstatic.net/4zZ0z.jpg
Despite pushing elements into the array within the loop, it remains empty once the loop concludes.