Created
October 17, 2023 15:36
-
-
Save kevboutin/6858f8eaa75c76a82d117ade4c16e1ed to your computer and use it in GitHub Desktop.
Convert Map to JSON
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 mapToJson = (map) => JSON.stringify(Object.fromEntries(map)); | |
const map = new Map([ | |
['user1', 'Alison'], | |
['user2', 'Kevin'], | |
['user3', 'James'], | |
]); | |
const json = mapToJson(map); | |
// {"user1":"Alison","user2":"Kevin","user3":"James"} | |
console.log(json); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment