In this article we will learn how to create a map from an array.
It is very common to create a map from an array in JavaScript.
Problem
We have a problem, which is that we want to create a map from the array
Imagine we have an array like this:
// Array
const array = [
['name', 'John'],
['age', 30],
];
And we want to create a map from this array.
Solution:
// Array
const array = [
['name', 'John'],
['age', 30],
];
// Convert to map
const map = new Map(array);
// Result:
console.log(map);
Output
Map(2) { 'name' => 'John', 'age' => 30 }
Thank you for reading
Thank you for reading my blog. 🚀