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

178
Views
Javascript boolean expression not working properly

Please I need help on this code. I have created a page with a single input field with the name="searchWork" where I input the search keyword and send.

On the "if" statement where the boolean resides, only the first comparison works (the comparison against the .state element, but the .lgaName and the .nameOfCommunity are not working. That is whenever I search the states in my object array, the object get populated with relevant data, but when I searched lga or community name, it displays an empty object, meaning the object is not populated with any data. I don't know where I went wrong on the comparison or something.

Thank you.

function getSearch(req, res, next) {
    let theProjects = shared.projects;
    let dataObject = {};
    const search = req.body.searchWork;
    for (let i = 0; i < theProjects.length; i++) {
        if ((search === theProjects[i].state) || (search === theProjects[i].lga[i].lgaName) || (search === theProjects[i].lga[i].communities[i].nameOfCommunity)) {
            dataObject.state = theProjects[i].state;
            dataObject.lga = theProjects[i].lga[i].lgaName;
            dataObject.community = theProjects[i].lga[i].communities[i].nameOfCommunity;
            dataObject.project = theProjects[i].lga[i].communities[i].projects.building;
        }
    }
    console.log(dataObject);

    next();
}
about 4 years ago · Juan Pablo Isaza
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!