JavaScript Map Methods

Beginner
4 min read
Updated: Nov 2026
12 method guides
Method index

About This Index

This page is the JavaScript Map Methods index for the tutorial track. Each row links to a full guide with syntax, three runnable examples, browser notes, and FAQs.

Learn what a Map is on /js/map. Use this page when you need a specific API such as set(), get(), or Map.groupBy().

Keys can be anything.

Strings, numbers, objects, NaN, and more all work as keys. Keys are compared with SameValueZero (NaN equals NaN; +0 and -0 are the same).

How to Call a Map Method

Instance methods use a dot on the Map. The one static helper is Map.groupBy:

JavaScript
const map = new Map();

map.set("role", "admin");  // store a value (returns map)
map.get("role");           // "admin"
map.has("role");           // true
map.delete("role");        // true
map.clear();               // empty the Map
map.size;                  // 0

// Iterators (insertion order)
for (const [k, v] of map) { /* ... */ }
map.keys(); map.values(); map.entries();
map.forEach(function (value, key) { /* ... */ });

// Static helper (ES2024)
Map.groupBy(items, function (item) { return item.type; });

// Newer upsert methods: check support first
map.getOrInsert("role", "guest");
map.getOrInsertComputed("role", function (key) { return "guest"; });

JavaScript Map Methods Table

All method guides in this JavaScript tutorial series (12 tutorials), grouped by what they do.

Store and update

3 methods

Write a value for a key. set() always writes; the two newer upsert methods write only when the key is missing.

MethodDescriptionTutorial
set()Store a value for a key. Returns the Map, so calls can be chained. Any key type works.Open
getOrInsert()Read the value for a key, or store a default first when the key is missing (newer method).Open
getOrInsertComputed()Read the value for a key, or call a function to build and store it when the key is missing (newer method).Open

Read

2 methods

Look a key up without changing the Map. Neither method throws for a missing key.

MethodDescriptionTutorial
get()Read the value stored for a key, or undefined when the key is missing. Never throws.Open
has()Check whether a key is stored. Returns true or false and never throws.Open

Remove

2 methods

Delete one entry, or empty the whole Map in one call.

MethodDescriptionTutorial
delete()Remove one entry by key. Returns true if something was removed, false otherwise.Open
clear()Remove every entry. The Map object stays the same. Returns undefined.Open

Loop over a Map

4 methods

Walk keys, values, or entries in insertion order. Map is iterable, so for...of works too.

MethodDescriptionTutorial
keys()Get an iterator of the keys in the order they were added.Open
values()Get an iterator of every value in the Map, in the order the keys were added.Open
entries()Get an iterator of [key, value] pairs. This is also what for...of uses on a Map by default.Open
forEach()Run a function once for every entry. The callback gets value first, then key.Open

Static helper

1 method

Build a Map of groups from a list without creating the Map yourself first.

MethodDescriptionTutorial
Map.groupBy()Build a new Map that groups items from a list under keys your function chooses (static helper).Open

Map Constructor and Members

Here is how to create a Map and the members it has. Compare this with a WeakMap, which has no size, no clear(), and cannot be looped over.

MemberWhat it gives youSince
new Map()Create an empty Map.ES2015
new Map([[k, v], ...])Create a Map that already holds some pairs. Keys can be any value.ES2015
map.sizeHow many entries the Map holds right now.ES2015
map.clear()Remove every entry in one call.ES2015
map.keys(), values(), entries(), forEach()Walk the Map in insertion order. See the method guides linked above.ES2015
for (const [k, v] of map)Maps are iterable. for...of yields [key, value] pairs.ES2015
Map.groupBy(items, callbackFn)Static helper: build a Map of groups from a list (ES2024).ES2024

Frequently Asked Questions

Classic instance methods are set(), get(), has(), delete(), clear(), keys(), values(), entries(), and forEach(). Two newer upsert methods are getOrInsert() and getOrInsertComputed(). Map.groupBy() is a static helper added in ES2024. A Map also has a size property and is iterable with for...of.
Yes. Strings, numbers, objects, functions, NaN, and more all work as keys. Keys are compared with SameValueZero: NaN equals NaN, and +0 and -0 count as the same key. Object keys match by identity, not by shape.
The Map hub teaches what a Map is, how keys compare, and when to prefer Map over a plain object. This index lists every method tutorial, plus the constructor and members such as size and clear(), so you can jump straight to the API you need.
Put a dot after the Map for instance methods: map.set(k, v), map.get(k), map.has(k), map.delete(k), map.clear(), and the iterators. The one static helper is Map.groupBy(items, callbackFn).
getOrInsert() and getOrInsertComputed() are still arriving in engines, so test before you rely on them. Map.groupBy() is ES2024. set(), get(), has(), delete(), clear(), keys(), values(), entries(), forEach(), and size have been in JavaScript since ES2015.

Start with set()

Learn how to store a value for any key, and why set() returns the Map for chaining.

set() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful