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

271
Vistas
How to add condition on foreach while looping through objects?

How to add condition on foreach while looping through objects?

Hey i m working on a task that takes the excel sheet data and outputs it in a HTML list. the output is array of objects that has all the data(column-wise) from user checked boxes. The issue is that if i select more than one checkbox then the for each loop through the excel data again and the output has duplicate data. How can i add a condition so that it check in the foreach loop whether the data is printed or not?

    var check_boxes = Array.from(document.querySelectorAll("input[type=checkbox]:checked")).map(checkbox => checkbox.value);
    console.log("check_boxes ", check_boxes);
    let getData = [];
    for (var i = 0; i < check_boxes.length; i++) {
        rowObject.forEach((entity) => {
            let obj = {};
            check_boxes.forEach((header) => {
                obj[header] = entity[header]

                console.log('obj', obj);
                getData.push(obj);
            })
            console.log("finalData ", getData);
        })
        createListElement(getData);
    }

}

function createListElement(arr) {
    // var element = arr;
    // childNode.style.listStyle = "none";
    // Set   
    const paraentDiv = document.getElementById('userdata');
    arr.forEach((item) => {
        let childNode = document.createElement("li");
        childNode.classList.add("userDataSpan");
        // childNode.innerHTML = JSON.stringify(item);

        childNode.style.listStyleType = "none";
        let str = ''
        for (const prop in item) {
            str += `<label class="userItems">${prop}</label>- <span class="">${item[prop]}</span>`;
        }
        childNode.innerHTML = str;
        paraentDiv.append(childNode);
    })

    // Add DOM Node to list
    // document.getElementById("userdata").appendChild(childNode);
}
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