I need to check if 2 values in an array of inputs are the same, in order to remove the duplicates.
I have tried a single for loop which compares i
const input1 = document.querySelector("#a")
const input2 = document.querySelector("#b")
const unsafeInputs = [input1, input2]
function checkInputs() {
for (let i = 0, j = unsafeInputs.length; i < j; i++) {
if (unsafeInputs[i].value === unsafeInputs[j].value) {
console.log("values are same")
unsafeInputs[i].value = ""
}
}
}
input1.onchange = function() {
checkInputs()
}
<input id="a">
<input id="b">