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);
}