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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *