Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

272
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda