Created
September 26, 2019 08:00
-
-
Save adamrosloniec/9cd5d5135ec7e94ce10d177d28fefb94 to your computer and use it in GitHub Desktop.
JS - Convert (replace) or Map - key to value from object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertState(state) { | |
const states = { | |
'new-south-wales': 'NSW', | |
'queensland': 'QLD', | |
'south-australia': 'SA', | |
'western-australia': 'WA', | |
'northern-territory': 'NT', | |
'victoria': 'VIC', | |
'tasmania': 'TAS', | |
'australian-capital-territory': 'ACT', | |
}; | |
if (states.hasOwnProperty(state)) { | |
return states[state]; | |
} | |
return null; | |
} | |
// example: convertState('victoria') | |
// return 'VIC' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment