Map.prototype.keys()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

La méthode keys() renvoie un objet Iterator qui contient les clés de chaque élément de l'objet Map, dans leur ordre d'insertion.

Exemple interactif

const map1 = new Map();

map1.set("0", "foo");
map1.set(1, "bar");

const iterator1 = map1.keys();

console.log(iterator1.next().value);
// Expected output: "0"

console.log(iterator1.next().value);
// Expected output: 1

Syntaxe

js
maMap.keys();

Valeur de retour

Un nouvel objet Iterator Map.

Exemples

Utiliser keys()

js
var maMap = new Map();
maMap.set("0", "toto");
maMap.set(1, "truc");
maMap.set({}, "bidule");

var mapIter = maMap.keys();

console.log(mapIter.next().value); // "0"
console.log(mapIter.next().value); // 1
console.log(mapIter.next().value); // Object

Spécifications

Specification
ECMAScript® 2025 Language Specification
# sec-map.prototype.keys

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
keys

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi