Junior — Middle
Explain what a Map data structure is and how it is typically used in programming.
sobes.tech AI
Answer from AI
Map is a data structure that stores key-value pairs. Each key is unique and associated with a specific value. In programming, Map is used for fast lookup, insertion, and deletion of data by key.
For example, in JavaScript (Node.js), Map can be used as follows:
const map = new Map();
map.set('user1', {name: 'Ivan', age: 30});
map.set('user2', {name: 'Maria', age: 25});
console.log(map.get('user1')); // {name: 'Ivan', age: 30}
Map is useful when you need to store and quickly retrieve data by a unique identifier, such as caching query results or storing user settings.