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

242
Views
No se puede leer la propiedad 'forEach' de JavaScript de error indefinido

este es mi código javascript, pero cada vez que intento ejecutarlo, arroja 'Error: TypeError: No se puede leer la propiedad 'forEach' de undefined' ¿Alguien puede decirme por qué sucede esto y también darme una solución cómo solucionarlo?

 app.post('/getElements', (req, res) => { fs.readFile('items.json', function(error, data) { if (error) { res.status(500).end() } else { try { const accountId = req.body.accountId //the value of it is 'data' const items = JSON.parse(data) items.accountId.forEach(function(item) { const price = item.price res.json({ price: price }) }) } catch (err) { console.log('Error: ', err) } } }) })
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Recomendaría verificar si los datos que ingresan tienen el formato que necesita, luego solo ejecute su forEach si accountId es un tipo de matriz. Si no, devuelve algo como price not available

about 4 years ago · Juan Pablo Isaza Report
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!