519 B
519 B
title, shortTitle, tags, expertise, author, cover, firstSeen
| title | shortTitle | tags | expertise | author | cover | firstSeen |
|---|---|---|---|---|---|---|
| Convert Map to object | Map to object | object | intermediate | chalarangelo | blog_images/succulent-1.jpg | 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}