1๐
โ
We are using Set
object is to remove the duplicates from an input which could be any iterable value. i.e. string
or an array
.
- If we are passing a string, it will check character by character and remove duplicate characters.
- If we are passing an array, it will check element by element and remove the duplicate elements.
As per your requirement, First you have to convert that countries string into an array by using Array.split()
method and then you can remove the duplicate names.
Live Demo :
const country = "Poland, France, Germany, Poland, Latvia, Estonia, Germany, Germany, France";
const arr = country.split(', ');
console.log([...new Set(arr)].join());
๐คDebug Diva
2๐
Try to split the string by ', '
and create the set based on the array from the split result :
this.country = [...new Set(this.result.results.country.split(', '))];
1๐
You should split the CSV string
mounted () {
this.country = [...new Set(this.result.results.country.split(',')];
}
๐คArik
Source:stackexchange.com