Skip to content

Instantly share code, notes, and snippets.

@adamrosloniec
Created September 26, 2019 08:00
Show Gist options
  • Save adamrosloniec/9cd5d5135ec7e94ce10d177d28fefb94 to your computer and use it in GitHub Desktop.
Save adamrosloniec/9cd5d5135ec7e94ce10d177d28fefb94 to your computer and use it in GitHub Desktop.
JS - Convert (replace) or Map - key to value from object
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