JS: Map.prototype.values

By Xah Lee. Date: . Last updated: .

New in JS2015.

mapObj.values()
Return a Iterable Object (also is a Iterator) for the values in the map mapObj.
// example of the values method of map
const xx = new Map([[3, "n3"], [4, "n4"], [5, "n5"]]);

for (let k of xx.values()) console.log(k);
// prints
// n3
// n4
// n5

This example shows the result is iterator and iterable:

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

console.log(xx.values); // [Function: values]
// result is a function that returns a iterator object

// call it
console.log(xx.values()); // MapIterator { 1, 3 }
// result is a iterator object

// is also a iterable
console.log(
  Reflect.has(xx.values(), Symbol.iterator),
);
BUY ΣJS JavaScript in Depth