Files
30-seconds-of-code/snippets/object-to-map.md
2023-04-28 22:29:23 +03:00

479 B

title, type, shortTitle, tags, author, cover, dateModified
title type shortTitle tags author cover dateModified
Convert object to Map snippet Object to Map
object
chalarangelo succulent-2 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}