This is the dropdown list box. I want to remove the duplicate \"Apple\" using javascript.
In ES3 POJS you could do this.
Javascript
function removeDuplicateOptions(selectNode) {
if (typeof selectNode === "string") {
selectNode = document.getElementById(selectNode);
}
var seen = {},
options = [].slice.call(selectNode.options),
length = options.length,
previous,
option,
value,
text,
i;
for (i = 0; i < length; i += 1) {
option = options[i];
value = option.value,
text = option.firstChild.nodeValue;
previous = seen[value];
if (typeof previous === "string" && text === previous) {
selectNode.removeChild(option);
} else {
seen[value] = text;
}
}
}
removeDuplicateOptions("Fruits");
On jsfiddle