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

273
Views
Variable does not increment outside of MAP Async/Await

I have this little code that is giving me a little doubt. Despite entering the IF, when trying to call a variable totalOnline or TotalOffline, it always appears as 0, as if it is not incrementing, but when I put or console.log inside the map function, I see that it is actually incrementing. How can I solve this simply and correctly?

const Zabbix = require('zabbix-promise')

const zabbix = new Zabbix({
    url: 'URL',
    user: 'USER',
    password: 'PASSWORD'
});


(async () => {
    await zabbix.login()
    let totalOffline = 0
    let totalOnline = 0
    var statusValue = null

    const host = await zabbix.request('host.get', {
        selectInterfaces: 'extend',
    })


    host.map(async (e, i) => {
        statusValue = await zabbix.request('item.get', {
            "output": "extend",
            "hostids": e.hostid,
            "search": {
                "key_": "icmpping",
                "name": "ICMP Ping"
            },
            "sortfield": "name"
        })

        statusValue ? await totalOnline++ : await totalOffline++
    })

    console.log(totalOnline)
})()
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!