Created
October 17, 2023 15:35
-
-
Save kevboutin/058fcd38f3feda6021df8b83bc798020 to your computer and use it in GitHub Desktop.
Convert JSON to a Map
This file contains hidden or 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
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