Map Simulator
A Map stores unique keys associated with values. Calling set(key, value) inserts a new entry or updates an existing key. JavaScript Maps preserve insertion order during iteration.
SetAverage O(1)
GetAverage O(1)
HasAverage O(1)
DeleteAverage O(1)
Map operations
Map insertion order
Example Map loaded. Choose an operation.
Map size0
Current key—
Last result—
Iteration orderInsertion order
Contact directory
Operation history
- No operations yet.
Current Map content
new Map()
Operation result
—
Map concepts
Unique keys
A Map can contain only one entry for a given key. Setting the same key again replaces its value without changing the Map size.
Insertion order
Updating an existing key does not move it to the end. Deleting and then inserting it again creates a new insertion position.
Map versus Object
Maps accept keys of any type, provide a direct size property, and are designed for frequent insertion, lookup, and deletion.
Safe rendering
User-supplied names and emails are rendered with DOM text nodes rather than interpreted as HTML or inline JavaScript.
Core JavaScript Map API
| Method / property | Purpose |
|---|---|
| map.set(key, value) | Insert or update an entry; returns the Map. |
| map.get(key) | Return the value or undefined. |
| map.has(key) | Test whether a key exists. |
| map.delete(key) | Remove an entry and return a Boolean. |
| map.size | Return the number of entries. |
| map.clear() | Remove all entries. |