Skip to content

Instantly share code, notes, and snippets.

@kevboutin
Created October 17, 2023 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevboutin/058fcd38f3feda6021df8b83bc798020 to your computer and use it in GitHub Desktop.
Save kevboutin/058fcd38f3feda6021df8b83bc798020 to your computer and use it in GitHub Desktop.
Convert JSON to a Map
const jsonToMap = (json) => new Map(Object.entries(JSON.parse(json)));
const json = '{"user1":"Alison","user2":"Kevin","user3":"James"}';
const map = jsonToMap(json);
// Kevin
console.log(map.get('user2'));
// Map(3) { 'user1' => 'Alison', 'user2' => 'Kevin', 'user3' => 'James' }
console.log(map);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment