EN
JavaScript - map() method over Map object keys
0 points
In this article, we would like to show you how to use the map()
method over Map object keys in JavaScript.
In the example below, we use:
Array.from()
method to return theresult
as an array,keys()
method to getmyMap
keys,map()
method to iterate over the keys and increment them
xxxxxxxxxx
1
const myMap = new Map([
2
[1, 'A'],
3
[2, 'B'],
4
[3, 'C'],
5
]);
6
7
const result = Array.from(myMap.keys()).map((key) => {
8
return key + 1;
9
});
10
11
console.log(result);
Output:
xxxxxxxxxx
1
[ 2, 3, 4 ]