Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!