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

291
Views
Replace array elements based on dictionary in javascript

I have a dictionary like this :

var iso_map = {'AFG':'AF','ALB':'AL','DZA':'DZ','ASM':'AS','AND':'AD','AGO':'AO','AIA':'AI','ATA':'AQ','ATG':'AG'}

I have an array like this :

var isoCodes = ['AFG','AFG','AFG','AGO,'AGO','AFG','AFG','AND','AGO']

I want to replace the above array to give me an output like this:

var isoCodes - ['AF','AF','AF','AO,'AO','AF','AF','AD','AO']
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just use map

var iso_map = {'AFG':'AF','ALB':'AL','DZA':'DZ','ASM':'AS','AND':'AD','AGO':'AO','AIA':'AI','ATA':'AQ','ATG':'AG'};

var isoCodes = ['AFG','AFG','AFG','AGO','AGO','AFG','AFG','AND','AGO']

var result = isoCodes.map(x => iso_map[x]);

console.log(result);

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!