Files
30-seconds-of-code/snippets/map-to-object.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

479 B

title, shortTitle, tags, author, cover, firstSeen
title shortTitle tags author cover firstSeen
Convert Map to object Map to object object chalarangelo succulent-1 2022-06-16T05:00:00-04:00

Converts a Map to an object.

  • Use Map.prototype.entries() to convert the Map 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}