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

223
Views
Why my .find() is sending undefined after getting conditional result true in express js
const data = {
    employees: require("../data/employees.json"),
    setEmployees: function (data) { this.employees = data; }

};

const getAllEmployeesData = (requestt, responsee) => {
    responsee.json(data.employees)
}

const getSpecificEmployee = (req, res) => {
    const employee = data.employees.find((emp) => { emp.id === parseInt(req.params.id);});
    if (!employee) {
        return res.status(400).json({ "message": `Employee ID ${req.params.id} not found` });
    }
    const filteredArray = data.employees.filter(emp => emp.id === parseInt(req.body.id));
    data.setEmployees([...filteredArray])
    res.json(data.employees);
}

in this line const employee = data.employees.find((emp) => { emp.id === parseInt(req.params.id);}); in above code employee is showing undefined but the conditional statement is returning true and also no such error like MODULE NOT FOUND that means nothing is wrong while importing my employee.json

my employees.json file

[ { "id": 1, "firstname": "hello", "lastname": "bye" }, {
"id": 2, "firstname": "you", "lastname": "me" } ]

about 4 years ago · Santiago Trujillo
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!