Categories
TypeScript Answers

How to initialize a map containing arrays in TypeScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.