const mainMap = new Map(); mainMap.set('key1', 'value1'); mainMap.set('key2', 'value2'); mainMap.set('key3', 'value3'); mainMap.set('key4', 'value4'); console.log(mainMap.size);
In this code, we created a new Map called mainMap and used the “set()” method to add four key-value pairs.
In the next step, we used the “size” property to get the number of key-value pairs stored in the Map.
The output is 4, suggesting four key-value pairs in mainMap.
Niva Shah is a Software Engineer with over eight years of experience. She has developed a strong foundation in computer science principles and a passion for problem-solving.