EN
TypeScript - create Map
0 points
In this article, we would like to show you how to create a Map in TypeScript.
xxxxxxxxxx
1
const myMap = new Map<string, number>();
xxxxxxxxxx
1
const myMap = new Map<string, string>([
2
['key1', 'value1'],
3
['key2', 'value2'],
4
['key3', 'value3'],
5
]);
In this example, we create a Map containing letters as its keys (string
type) and ASCII codes as values (number
type).
xxxxxxxxxx
1
const myMap = new Map<string, number>([
2
['A', 65],
3
['B', 66],
4
['C', 67],
5
]);