Files
30-seconds-of-code/snippets/objectToMap.md
Chalarangelo 126134a489 Fix typos
2022-09-04 13:49:46 +03:00

500 B

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