EN
TypeScript - get Map size
0 points
In this article, we would like to show you how to get Map size in TypeScript.
Quick solution:
xxxxxxxxxx
1
myMap.size;
In this example, we use Map size
property accessor to get the number of elements in a Map object.
xxxxxxxxxx
1
const myMap = new Map<string, string>([
2
['key1', 'value1'],
3
['key2', 'value2'],
4
['key3', 'value3'],
5
]);
6
7
const size: number = myMap.size;
8
9
console.log(size); // 3
Output:
xxxxxxxxxx
1
3