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:
[ { "name": "a", "value": "1", }, { "name": "b", "value": "2", } ]
You could take Array.from and map the key/value pairs.
Array.from
let map = new Map().set('a', 1).set('b', 2), array = Array.from(map, ([name, value]) => ({ name, value })); console.log(array);
1.4m articles
1.4m replys
5 comments
57.0k users