I'm populating multiple dropdowns with the same data.
How do I set the selected value from the array below for each iteration?
const arraylist = ['Tom', 'Joe', 'Bill'];
const iterable = ['Mark', 'Jill', 'Ben', 'John', 'Tom', 'Joe'];
let dropdown = '';
for (let i = 0; i < 5; i++) {
dropdown += "<select name='samedata' class='dropdownlist'>";
for (const [index, v] of Object.entries(iterable)) {
let checked = arraylist.includes(v) ? 'selected' : '';
dropdown += `<option value="${v}" ${checked}>${v}</option>`;
}
dropdown += '</select>';
}
Where the first dropdown having Tom selected, second having Joe and the rest having nothing selected.