Example: Code error remove duplicates dropdown

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};
});
}
});

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

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