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.
A Map stores unique keys associated with values. Calling set(key, value) inserts a new entry or updates the value of an existing key. JavaScript Maps preserve insertion order during iteration.
Example Map loaded. Choose an operation.
new Map()
—
A Map can contain only one entry for a given key. Setting the same key again replaces its value without changing the Map size.
Updating an existing key does not move it to the end. Deleting and then inserting it again creates a new insertion position.
Maps accept keys of any type, provide a direct size property, and are designed for frequent insertion, lookup, and deletion.
User-supplied names and emails are rendered with DOM text nodes rather than interpreted as HTML or inline JavaScript.
| 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. |