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

270
Visualizações
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 à 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