I have dynamically created dropdowns and populating them with data from a json array.
Data:
data = [{hello: 'abc', asd: '123', fgh: '345' },
{hello: 'sdf', asd: '456', fgh: 'df' },
{hello: 'ty', asd: '789', fgh: '345675' },
{hello: 'qwe', asd: '123', fgh: '987' }]
array of keys (for the data I need in the dropdown): arr = ['asd', 'fgh']
Creation of dropdown:
arr.forEach(c => {
$('div').append(`
<div class='float-left'>
<p>${c}</p>
<select id='${c}'></select>
</div>`);
});
To populate the dropdowns:
arr.forEach(o => {
data.forEach(strs => {
if (strs[o] != null) {
$(`#${o}`).append(`<option value='${strs[o]}'>${strs[o]}</option>`);
}
});
});
I am able to populate the dropdowns. How do I populate the dropdowns with NO DUPLICATES?