How to Create an Array From a Map in JavaScript
In this lesson, we will see how to create an array from a map in JavaScript, sometimes we want to convert a given map to an array in JavaScript so how can we do that?
The Array.from() method
To do that we can use the Array.from() method that creates a new array from a given map.
const myMap = new Map([['name','john'],['age',22],['city','london']]);
console.log(Array.from(myMap));
//(3) [Array(2), Array(2), Array(2)]
// 0 : (2) ['name', 'john']
// 1 : (2) ['age', 22]
// 2 : (2) ['city', 'london']
//length : 3