How to Create an Empty Map in JavaScript ?
Last Updated :
01 Feb, 2024
In JavaScript, you can create an empty Map using the Map
constructor. whenever we initialize any map it is empty at first and we need to declare the key-value pair inside the map constructor to construct the map having values.
Syntax:
let emptyMap = new Map();
Example: Here, initialMap
is a Map that has been initialized with key-value pairs.
let initialMap = new Map([
['key1', 'value1'],
['key2', 'value2'],
// more key-value pairs if needed
]);
Share your thoughts in the comments
Please Login to comment...