Hello
I’ve tested multiple tutorials but none seem to work.
I have a dropdown via “Connect a list” and have many duplicates.
Here you can see my code.
import wixData from 'wix-data';
export function iRegion_change(event, $w) {
wixData.query('Jobs')
// Query the collection for any items whose "Name" field contains
// the value the user selected in the dropdown
.contains('regio', $w('#iRegion').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("Jobs")
// 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("#iRegion").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};
});
}
});
1 Like
Hi Anseric,
Welcome to the Wix Code forums.
Take a look at the forum post Remove duplicates from connected dropdown options . You’re not the first to ask about this 
Good luck,
Yisrael
Hello
Sadly enough I tried his method but it doesn’t seem to work.
I’ve read the comments but no solution at first sight. I’m missing something on how to create my dropdown I guess but can’t seem to figure it out.
Thanks anyway!
Make sure that you disconnect the dropdown list items from the collection:

I hope this helps. If not, please post the URL of your site. Only authorized Wix personnel can get access to your site in the editor.
Hello
I’ve tried that but it doesn’t seem to work.
If i disconnect another list is used.
Hello
Is it possible to take a look? I want the dropdown to show regions but no duplicates.
And if possible an “All Regions” option.
https://www.digitalents.be/test-search
Hi Anseric,
I tried this out and the dropdown list looks just fine - no duplicates.
To get the correct field, change your function to use item.regio :
function getUniqueregio(items) {
// Use the map method to create the titlesOnly object containing all the titles from the query results
const regioOnly = items.map(item => item.regio); // changed
// Return an array with a list of unique titles
return [...new Set(regioOnly)];
}
There is a duplicate in the dropdown list:
The reason for that is that one of the items in the database has a space added to the end of the region name, which makes it different than the others:

Notice the space before the cursor.
I hope this helps. Let me know how it goes.
Yisrael
Thanks Yisrael
I’ve been to close to see such a stupid mistake, thanks for the help!
Final Question.
I tried with the “All Continents” code but can’t get “All Region”
Hey Anseric,
Change this code:
// 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("#iRegion").options = buildOptions(uniqueTitles);
To this:
// 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
let newList = buildOptions(uniqueTitles);
newList.unshift({ // add "All Regions" to beginning of array
"value": '',
"label": 'All Regions'
});
$w("#iRegion").options = newList; // set the dropdown list
Have fun,
Yisrael
Yisreal, the problem I have is when you say in the 4th post down, “Make sure that you disconnect the dropdown list items from the collection:”
Once I do that how do I get my drop down to go to the correct Dynamic Page?
Dropdown no longer has duplicates, but now it doesn’t go anywhere when I select an item. Whereas before coding it, the item would take me to the correct Dynamic Page, but there were 20 of each item listed in the dropdown!
I’ve tried wix-location.to & that isn’t working. been at this for days
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady(function () {
// Run a query that returns all the items in the collection
wixData.query(“PartsList”)
// Get the max possible results from the query
.limit(1000)
.ascending(“title”)
.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(“#iManufacturer”).options = buildOptions(uniquetitles);
});
$w(“#iManufacturer”).placeholder = “Products by Manufacturer”;
// 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};
});
}
});
export function iManufacturer_change(event, $w) {
$w(“#dataset1”).setCurrentItemIndex(event.target.selectedIndex)
.then( () => {
wixLocation.to($w(“#dataset1”).getCurrentItem().title);
} );
}