Reputation: 691
I'm trying to run a foreach loop and add values to an array, but it's not working properly. The values in the first foreach get added properly, but none of the values in the second foreach loop get added.
My code is:
categories.forEach(async function (cat) {
te.push({ params: { slug: [cat.cat_slug] } })
var articles = await db.query(escape`
SELECT *
FROM articles
WHERE category = ${cat.id}
`)
articles.forEach(function (art) {
te.push({ params: { slug: [cat.cat_slug, art.slug] } })
})
})
Any ideas?
Upvotes: 0
Views: 1613
Reputation: 691
According to this answer Using async/await with a forEach loop Async can't be used inside foreach loops, I had to use a for loop instead and it got fixed.
Upvotes: 1