[Vuejs]-Remove repeating text and quotes in Child component in Vue JS

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

Leave a comment