How to convert a Map into an Object in JavaScript?
NicolasBrondinBernard
Even though a Map looks like a regular object in JavaScript, converting from one to the other isn't always intuitive.

Article published on 28/03/2024, last updated on 10/08/2026
In JavaScript, a Map is a native class (since ES6) that makes it easy to create data dictionaries!
If you're wondering what the differences are between a JSON object (key-value) and a Map, you can read this article.

Let's take a very simplified example dictionary, like this:
const myMap = new Map();
myMap.set("a", "alternative");
myMap.set("b", "binoculaire");
myMap.set("c", "cyclomoteur");
To convert it to an Object type, simply use the fromEntries method of the Object class, like this:
const myObject = Object.fromEntries(myMap);
console.log(myObject);
// Output: { a: "alternative", b: "binoculaire", c: "cyclomoteur" }
And there you go, your dictionary is now stored in a classic JSON object!
Careful: The conversion only happens on a single level of depth, so if your Map contains other Maps, then your final Object will also contain those Maps.
Complete courses, exercises and certificates to really learn programming!
4.8 average rating
No comments yet