Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

240
Visualizações
How to remove a duplicate country from intl-tel-input

How to remove the repetition of preferred countries. I need to add all the African countries as preferred countries in the dropdown list.

code i used for that.

preferredCountries: [ "gh", "dz","ao","bj","bw","bf","bi","cm","cf","td","km","cd","dj","eg","gq","er","sz","et","ga","gm","gq","gw","ke","ls","lr","ly","mg","mw","ml","mr","mu","ma","mz","na","ne","ng","rw","sn","sc","sl","so","za","ss","sd","tz","tg","tn","ug","zm","zw" ],
But this same country's all are repeating in the list again. How can I remove the repetition.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can use a Set to get the unique values here, then use the ... spread operator to return to an array:

preferredCountries = [ "gh", "dz","ao","bj","bw","bf","bi","cm","cf","td","km","cd","dj","eg","gq","er","sz","et","ga","gm","gq","gw","ke","ls","lr","ly","mg","mw","ml","mr","mu","ma","mz","na","ne","ng","rw","sn","sc","sl","so","za","ss","sd","tz","tg","tn","ug","zm","zw" ];

const uniqueCountries = [...new Set(preferredCountries)];

console.log({ uniqueCountries });
.as-console-wrapper { max-height: 100% !important; top: 0; }

Another example:

const values = [ 'a', 'a', 'a', 'b', 'b', 'b', 'c' ];

// Use spread operator and new Set()
let uniqueValues = [...new Set(values)];

console.log({ uniqueValues });

// Or use Array.from() and new Set()
uniqueValues = Array.from(new Set(values));

console.log({ uniqueValues });
.as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Juan Pablo Isaza Relatório

0

You can avoid duplication of array by different ways

let preferredCountries: [ "gh", "dz","ao","bj","bw","bf","bi","cm","cf","td","km","cd","dj","eg","gq","er","sz","et","ga","gm","gq","gw","ke","ls","lr","ly","mg","mw","ml","mr","mu","ma","mz","na","ne","ng","rw","sn","sc","sl","so","za","ss","sd","tz","tg","tn","ug","zm","zw" ],

let NewpreferredCountries= [...new Set(chars)];

console.log(NewpreferredCountries);

Another Method is

let preferredCountries: [ "gh", "dz","ao","bj","bw","bf","bi","cm","cf","td","km","cd","dj","eg","gq","er","sz","et","ga","gm","gq","gw","ke","ls","lr","ly","mg","mw","ml","mr","mu","ma","mz","na","ne","ng","rw","sn","sc","sl","so","za","ss","sd","tz","tg","tn","ug","zm","zw" ],

let NewpreferredCountries= preferredCountries.filter((c, index) => {
    return preferredCountries.indexOf(c) === index;
});

console.log(NewpreferredCountries);

You can also remove duplicates from an array using forEach() and include()

let preferredCountries: [ "gh", "dz","ao","bj","bw","bf","bi","cm","cf","td","km","cd","dj","eg","gq","er","sz","et","ga","gm","gq","gw","ke","ls","lr","ly","mg","mw","ml","mr","mu","ma","mz","na","ne","ng","rw","sn","sc","sl","so","za","ss","sd","tz","tg","tn","ug","zm","zw" ],

let NewpreferredCountries= [];
preferredCountries.forEach((c) => {
    if (!NewpreferredCountries.includes(c)) {
        NewpreferredCountries.push(c);
    }
});

console.log(NewpreferredCountries);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda