Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda