How to turn the dropdown values into unique values

Hi, I am trying to solve a simple issue. I am pulling the data from Google Sheets, which was listed as "USA, Canada, UK". Then, I tried to use item.split(", ") so it can be displayed as Tags in the table. However, another extra work seems to be done in the dropdown as it is reading the original data, and it wasn't returning the data broken by comma, but the whole unique array. Is there a better way to turn it into the expected result (as shown below)?

Now

I tried to solve this by adding an extra query after it pulls the data successfully, so it can return a single unique value

let data = [];
let deliveryTeams = [];

for (let item of getServiceCatalogue.data) {
   deliveryTeams.push(item.Delivery_Teams);
}

deliveryTeams = deliveryTeams.join().split(",");

function removeDuplicates(deliveryTeams) {
    let unique = [];
    deliveryTeams.forEach(element => {
        if (!unique.includes(element.trim()) && element.trim() !== "") {
            unique.push(element.trim());
        }
    });
    return unique;
}

data = removeDuplicates(deliveryTeams);
console.log(data);
return data;

Expected

I have multiple columns with the same issue, so many queries are created to solve the issue. Is there a simple way to achieve the same, or how to reuse the query by passing a parameter? Thank you!

Hi @Nikki_Ip,

You could do this a few different way, but the easiest might be a transformer with something like this:

const deliveryTeams = serviceCatalogue.data.map(d => d.Delivery_Teams)
return _.uniq(deliveryTeams)

Lodash is included by default and you can use it's _.uniq function.

Without Lodash, as a one-liner you could do
[...new Set(serviceCatalogue.data.map(d => d.Delivery_Teams)]

1 Like

Thanks for the input. I tried to use the code above on the Data Source, but it seems doesn't work. Maybe I've missed something...

Then I solved this by adding this code to the Data Source

{{Array.from(new Set(getServiceCatalogue.data.flatMap(obj => obj.Delivery_Teams.split(', '))))}}