0

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']
2
  • simple map()..... Commented Oct 8, 2021 at 15:32
  • isoCodes = isoCodes.map(i=>iso_map[i]); easy home work Commented Oct 8, 2021 at 15:35

1 Answer 1

1

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);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.