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

274
Views
La variable no se incrementa fuera de MAP Async/Await

Tengo este codigo que me esta dando una pequeña duda. A pesar de ingresar el IF, cuando intento llamar a una variable totalOnline o TotalOffline, siempre aparece como 0, como si no se estuviera incrementando, pero cuando coloco o console.log dentro de la función de mapa, veo que en realidad se está incrementando. ¿Cómo puedo resolver esto de manera simple y correcta?

 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!