I want to remove all duplicated data and put on screen a select menu without these duplicated ones.
I’m having troubles to compare datas from my json and what is already on my page.
I think im not far but I can’t understand how to have the good datas to compare.
This is the html :
<select id="ville">
<option id="ville__option">Séléction de la ville</option>
</select>
This is the formula that I want to work but I don’t fine how to compare datas on my json and on my code.
G.handler_changeAca = async function(ev){
let rep = await fetch('asset/menesr-depp-dnb-session-2018.json');
let id = await rep.json();
let ville = document.querySelector('#ville');
let villePlace = document.querySelectorAll('#ville__option');
// let option = document.querySelectorAll('#ville__option');
// console.log(option[0].textContent);
const result = [];
for (let i = 0; i < id.length; i++) {
villePlace = document.querySelectorAll('#ville__option');
result.forEach(item => {
console.log(item);
if (villePlace.includes(item)){
return false
};
else {
let option = document.createElement("option");
option.textContent = id[i]["Libellé commune"];
ville.appendChild(option, villePlace);
}
}
)};
}
let aca = document.querySelector('#aca');
aca.addEventListener('change', G.handler_changeAca)
If you need more information dont hesitate, thank you.