JSFiddle - React, Tailwind, and code Playground

by brigand

HTML

<pre id="out"></pre>

JavaScript

const asArray = (collection, fn) => new collection.constructor(fn(Array.from(collection)));

const map1 = new Map([[1, 'foo'], [2, 'bar']]);

const map2 = asArray(map1, items => items.filter(([key]) => key >=  2))

out.textContent = map2.constructor.name + ' ' + JSON.stringify(Object.fromEntries([...map2]))