const mainMap = new Map(); mainMap.set('key1', [1, 2, 3]); mainMap.set('key2', ['a', 'b', 'c']); console.log(mainMap.get('key1')); console.log(mainMap.get('key2'));
[ 1, 2, 3 ] [ 'a', 'b', 'c' ]
In this code, we created a new Map called mainMap.
In the next step, we used the set() method to add two key-value pairs to the Map.
The keys are ‘key1’ and ‘key2’, and the values are arrays [1, 2, 3] and [‘a’, ‘b’, ‘c’].
Finally, we used the get() method to retrieve the values associated with the keys ‘key1’ and ‘key2’, which are the arrays [1, 2, 3] and [‘a’, ‘b’, ‘c’].
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.