Files
30-seconds-of-code/snippets/js/s/object-to-map.md
2023-05-10 22:35:09 +03:00

501 B

title, type, shortTitle, language, tags, author, cover, dateModified
title type shortTitle language tags author cover dateModified
Convert object to Map snippet Object to Map javascript
object
chalarangelo yellow-shoes 2022-06-16T05:00:00-04:00

Converts an object to a Map.

  • Use Object.entries() to convert the object to an array of key-value pairs.
  • Use the Map constructor to convert the array to a Map.
const objectToMap = obj => new Map(Object.entries(obj));
objectToMap({a: 1, b: 2}); // Map {'a' => 1, 'b' => 2}