Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Can Change Variable Insıde Function?
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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!