# Example: Code error remove duplicates dropdown

**URL:** <https://forum.wixstudio.com/t/example-code-error-remove-duplicates-dropdown/27531>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [November 12, 2020, 7:47pm UTC](https://forum.wixstudio.com/t/example-code-error-remove-duplicates-dropdown/27531 "2020-11-12T19:47:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kenanuenal](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/kenanuenal/32/21092_2.png) [@kenanuenal](https://forum.wixstudio.com/u/kenanuenal)\
**Post date:** [November 12, 2020, 7:47pm UTC](https://forum.wixstudio.com/t/example-code-error-remove-duplicates-dropdown/27531/1 "2020-11-12T19:47:57Z")

</div>

Hi Community,  
my…  
dropdown = dropdown2  
database = Team  
field key in database = nationalitat

(I think the reference example is about items and my field is nationalitat, where I have to do some changes - can anybody pls help

Thank you  
Yulia32

**imp** ort wixData from ‘wix-data’ ;  
export function dropdown2\_change(event, $w) {  
wixData.query( ‘Team’ )  
// Query the collection for any items whose “Name” field contains  
// the value the user selected in the dropdown  
.contains( ‘nationalitat’ , $w( ‘#dropdown2’ ).value)  
.find() // Run the query  
.then(res =\> {  
// Set the table data to be the results of the query  
$w( ‘#table1’ ).rows = res.items;  
});  
}

$w.onReady( function () {  
// Run a query that returns all the items in the collection  
wixData.query( “Team” )  
// Get the max possible results from the query  
.limit( 1000 )  
.find()  
.then(results =\> {  
// Call the function that creates a list of unique titles  
const uniqueTitles = getUniqueTitles(results.items);  
// Call the function that builds the options list from the unique titles  
$w( “#dropdown2” ).options = buildOptions(uniqueTitles);  
});  
// Builds an array from the “Title” field only from each item in  
// the collection and then removes the duplicates  
function getUniqueTitles(items) {  
// Use the map method to create the titlesOnly object containing all the titles from the query results  
const titlesOnly = items.map(item =\> item.title);  
// Return an array with a list of unique titles  
return [… new Set(titlesOnly)];  
}  
// Creates an array of objects in the form {label: “label”, value: “value”} from the array of titles  
function buildOptions(uniqueList) {  
return uniqueList.map(curr =\> {  
// Use the map method to build the options list in the format {label:uniqueTitle, value:uniqueTitle}  
return {label:curr, value:curr};  
});  
}  
});

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [November 12, 2020, 10:35pm UTC](https://forum.wixstudio.com/t/example-code-error-remove-duplicates-dropdown/27531/2 "2020-11-12T22:35:58Z")

</div>

(Too many comments inside. it’s hard to read).  
anyway now that we have the .distinct() method we can do it shorter:

```javascript
 wixData.query("Team").limit(1000).distinct("title")
.then(res => {
$w("#dropdown2").options = res.items.map(e => ({label: e, value:e}));
})

```
