Convert Map to object
JavaScript, Object · Jun 16, 2022

Converts a Map
to an object.
- Use
Map.prototype.entries()
to convert theMap
to an array of key-value pairs. - Use
Object.fromEntries()
to convert the array to an object.
const mapToObject = map => Object.fromEntries(map.entries());
mapToObject(new Map([['a', 1], ['b', 2]])); // {a: 1, b: 2}