Skip to content
Advertisement

How to convert Map to array of object?

i’m trying to convert a Map into array of object

Lets say I have the following map:

let myMap = new Map().set('a', 1).set('b', 2);

And I want to convert the above map into the following:

JavaScript

Advertisement

Answer

You could take Array.from and map the key/value pairs.

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement