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

167
Views
la variable global se devuelve vacía en node.js

Tengo una variable de "datos" que está en el alcance global de la función y la estoy actualizando dentro de la función interna para leer un archivo.

 function timeSeries(obj) { data = [ { original_value: [], forecasted_value: [], min_band: [], max_band: [], line_status: [], timestamp: [] } ] fs.readFile("./api/assignment_data/" + obj._id + ".json", "utf-8", function read(err, datas) { if (err) { throw err; } const filedata = JSON.parse(datas) data[0].original_value.push(filedata.map(line => line.original_value)) data[0].forecasted_value.push(filedata.map(line => line.forecasted_value)) data[0].min_band.push(filedata.map(line => line.min_band)) data[0].max_band.push(filedata.map(line => line.max_band)) data[0].line_status.push(filedata.map(line => line.line_status)) data[0].timestamp.push(filedata.map(line => line.timestamp)) console.log(data[0].original_value[0][0]) }) return data; }

cuando hago console.log en lugar de devolver datos o miro la variable, la función devuelve valor a... está vacía de la forma en que se declaró anteriormente. sin embargo, si hago console.log dentro de la función de lectura de archivos, se imprime con éxito

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!