coderef

Map getOrInsert()Baseline · Newly available

The getOrInsert() and getOrInsertComputed() methods of Map objects get a value, setting and getting a default value if needed.

Works in the latest version of every major browser, but older devices may not support it yet. Baseline since Feb 14, 2026.

Browser support

DesktopChrome
1–144Not supported
145+Supportedsince Feb 10, 2026
Current: 155
Edge
12–144Not supported
145+Supportedsince Feb 14, 2026
Current: 154
Firefox
1–143Not supported
144+Supportedsince Oct 14, 2025
Current: 157
Safari
1–26.1Not supported
26.2+Supportedsince Dec 12, 2025
Current: 27
MobileChrome Android
18–144Not supported
145+Supportedsince Feb 10, 2026
Current: 155
Firefox Android
4–143Not supported
144+Supportedsince Oct 14, 2025
Current: 157
Safari iOS
1–26.1Not supported
26.2+Supportedsince Dec 12, 2025
Current: 27

How to use

Every current browser supports this, but it only became Baseline on Feb 14, 2026. Use it as a progressive enhancement, or keep a fallback if you support older devices.

Example

Full syntax and examples are on MDN: getOrInsert.

Feature detection

JS · check before using
if ("getOrInsert" in Map || ("prototype" in Map && "getOrInsert" in Map.prototype)) {
  // Map.getOrInsert is available
}

Sub-features

Support for each part of the feature (4). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Map.getOrInsert14514514426.214514426.2
Map.getOrInsertComputed14514514426.214514426.2
WeakMap.getOrInsert14514514426.214514426.2
WeakMap.getOrInsertComputed14514514426.214514426.2