# Filter dropdown list to unique items lest using a data set

**URL:** <https://forum.code.org/t/filter-dropdown-list-to-unique-items-lest-using-a-data-set/40524>\
**Category:** Coding and Debugging Help\
**Created:** [March 11, 2025, 1:32pm UTC](https://forum.code.org/t/filter-dropdown-list-to-unique-items-lest-using-a-data-set/40524 "2025-03-11T13:32:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![estefaniaperezdelsol](https://avatars.discourse-cdn.com/v4/letter/e/a183cd/32.png) [@estefaniaperezdelsol](https://forum.code.org/u/estefaniaperezdelsol)\
**Post date:** [March 11, 2025, 1:32pm UTC](https://forum.code.org/t/filter-dropdown-list-to-unique-items-lest-using-a-data-set/40524/1 "2025-03-11T13:32:48Z")

</div>

A student of mine is trying to create a dropdown menu from a list that has multiple repeated values and wants it to display the unique, unrepeated values of the list.

Is there a way to filter a list to have just the unique values and then use that to make a dropdown menu? I don’t know what the command of setting unique values in a filtered list is.

---

<div class="post-metadata">

**Author:** ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)\
**Post date:** [March 12, 2025, 3:26am UTC](https://forum.code.org/t/filter-dropdown-list-to-unique-items-lest-using-a-data-set/40524/2 "2025-03-12T03:26:46Z")

</div>

you can use `indexOf` or `includes` depending on your use case  
by using the base array with all of the repeating values iterating through it using a `for` loop

```auto
var entries = ["a", "b", "a", "n", "c"];
var uniqueEntries = [];
for (var i = 0; i < entries.length; i++) {
  if (!uniqueEntries.includes(entries[i])) {
    uniqueEntries.push(entries[i]);
  }
}
console.log(uniqueEntries);

```

this prototype call would probably be best in your use case because you do not need the index of where the entry is within the original array which is what `indexOf` returns while `includes` returns a boolean value if it exists within the array

# Varrience

---

<div class="post-metadata">

**Author:** ![estefaniaperezdelsol](https://avatars.discourse-cdn.com/v4/letter/e/a183cd/32.png) [@estefaniaperezdelsol](https://forum.code.org/u/estefaniaperezdelsol)\
**Post date:** [March 12, 2025, 5:04pm UTC](https://forum.code.org/t/filter-dropdown-list-to-unique-items-lest-using-a-data-set/40524/3 "2025-03-12T17:04:59Z")

</div>

Thank you for responding. I just tried running this code and I get an error message that says that .includes is not a function. Is there another way of writing it?

---

<div class="post-metadata">

**Author:** ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)\
**Post date:** [March 12, 2025, 6:00pm UTC](https://forum.code.org/t/filter-dropdown-list-to-unique-items-lest-using-a-data-set/40524/4 "2025-03-12T18:00:44Z")

</div>

oh yes that’s weird… well anyways indexOf will work i know it has that

```js
var entries = ["a", "b", "a", "n", "c"];
var uniqueEntries = [];
for (var i = 0; i < entries.length; i++) {
  if (uniqueEntries.indexOf(entries[i]) < 0) {
    uniqueEntries.push(entries[i]);
  }
}
console.log(uniqueEntries);

```

I’ve tested it on CDO i thought it did have the includes prototype but i guess it must have been an es6 prototype
