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

269
Views
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
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!