519 B
519 B
title, type, shortTitle, language, tags, author, cover, dateModified
| title | type | shortTitle | language | tags | author | cover | dateModified | |
|---|---|---|---|---|---|---|---|---|
| Convert Map to object | snippet | Map to object | javascript |
|
chalarangelo | succulent-1 | 2022-06-16T05:00:00-04:00 |
Converts a Map to an object.
- Use
Map.prototype.entries()to convert theMapto 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}