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

96
Views
res.data.forEach no es una función en Jquery

Tengo un error: TypeError no detectado: res.data.forEach no es una función

cuando uso forEach con axios.get. ¿Cómo puedo resolver el problema?

guion:

 let totalData = []; let monthData = []; $(async function () { await axios.get(`/dashboard/chart/month`).then((res) => { console.log(res.data); res.data.forEach((data) => { totalData.push(data.total); monthData.push(data.months); }); }); });

Datos:

 { "success": true, "data": [ { "months": "January 21", "total": 0 }, { "months": "February 21", "total": 0 }, { "months": "March 21", "total": 0 }, { "months": "April 21", "total": 0 } ], "msg": null }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ah, me acabo de dar cuenta. Mire su res.data y necesita res.data.data . Reemplace su código con:

 let totalData = []; let monthData = []; $(async function () { await axios.get(`/dashboard/chart/month`).then((res) => { console.log(res.data); // Add another data here: res.data.data.forEach((data) => { totalData.push(data.total); monthData.push(data.months); }); }); });

El res.data es la versión de Axios. Tiene tus datos + estado y otras cosas. También tienes tus data . Entonces necesitas res.data.data .

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!