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

219
Views
Sails.js Encuentra el error javascript por id

Quisiera mostrar solo un alumno.pero hay el error de decirme que no es una funcion


Código actual

 detail: async function (req, res) { var thatEvent = await Event.findOne(req.params.eventid); if (!thatEvent) return res.notFound(); var event = await Event.findOne(req.params.eventid).populate( "participants" ); if (!event) return res.notFound(); var participants = await event.participants; return res.json(participants); },

El es el resultado del código actual.

 [ { "createdAt": 1636793903089, "updatedAt": 1636793903089, "id": 3, "role": "student", "username": "student1" }, { "createdAt": 1636793903089, "updatedAt": 1636793903089, "id": 4, "role": "student", "username": "student2" }, { "createdAt": 1636793903089, "updatedAt": 1636793903089, "id": 5, "role": "student", "username": "student3" } ]



Después del cambio

 detail: async function (req, res) { var thatEvent = await Event.findOne(req.params.eventid); if (!thatEvent) return res.notFound(); var event = await Event.findOne(req.params.eventid).populate( "participants" ); if (!event) return res.notFound(); var participants = await event.participants.find({id:3}); return res.json(participants); },

Luego mostrará el error que no es una función.

 error: Sending 500 ("Server Error") response: TypeError: #<Object> is not a function at Array.find (<anonymous>) at Object.detail [as event/detail]

El código que edité está abajo.

 var participants = await event.participants.find({id:3});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Refiero el sitio web aquí para modificar mi código. El resultado es correcto ahora.
https://www.codegrepper.com/code-examples/javascript/array.find+find+is+not+a+function

 var participants = await event.participants.find(({ id }) => id === 3);

El resultado

 { "createdAt": 1636793903089, "updatedAt": 1636793903089, "id": 3, "role": "student", "username": "student1" }
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!