notifications.forEach((element,index) => {
element.data = JSON.parse(element.data)
if(element.data.user){
db.query(`select * from users where id=${element.data.user}`,(err,user) => {
if(user[0]){
element.username = user[0].username
element.name = 'post'
}
})
}
if(element.data.post){
db.query(`select * from posts where id=${element.data.post}`,(err,post) => {
if(post[0]){
element.pType = post[0].type
element.pSlug = post[0].slug
element.pTitle = post[0].title
}
})
}
delete element.data
notifications[index] = element
});
Element changing inside db.query but outside of function element stay same with first time. How can I fix it?