Sometimes, we want to initialize a map containing arrays in TypeScript.
In this article, we’ll look at how to initialize a map containing arrays in TypeScript.
How to initialize a map containing arrays in TypeScript?
To initialize a map containing arrays in TypeScript, we can use the Map
type.
For instance, we write
const map: Map<string, string[]> = new Map();
to create a Map
instance with the Map<string, string[]>
type.
The first type is the keys’ types and the 2nd type is the values’ types.
Conclusion
To initialize a map containing arrays in TypeScript, we can use the Map
type.