JS: Map.prototype.keys

By Xah Lee. Date: . Last updated: .

(new in JS: ECMAScript 2015)

mapObj.keys()

Return a Generator for the keys in the map.

console.log(
  JSON.stringify(
    Array.from(
      (new Map([[3, "n3"], [4, "n4"], [5, "n5"]])).keys(),
    ),
  ) === `[3,4,5]`,
);

Verify Result is a Generator

// verify the result is iterator and iterable

const xx = (new Map([[1, 2], [3, 4]])).keys();

// is iterable
console.log(Reflect.has(xx, Symbol.iterator));
// true

// is iterator
console.log(Reflect.has(xx, "next"));
// true

JS Map.prototype