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!