Find method in javascript

app.get(‘/api/persons/:id’, (req, res)=> {
const id = Number(req.params.id);
const getPerson = persons.find(person =>
{
person.id === id? person
: “no person found”
});
console.log(getPerson)
})

why m i getting undefined? what m i doing wrong?

You aren’t quit using the find method correctly.

MDN: Array.prototype.find()

Pay special attention to the type of value the callback function you pass into find should return.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.