Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda