Maps and Sets
Map Entries
Turn map entries into display text.
Map Entries
map_entries.js
const prefix = "A";
const names = Array.from(
new Map([
["Ada", 2],
["Bo", 3],
["Cy", 4],
]).entries()
)
.filter((entry) => entry[0].startsWith(prefix))
.map((entry) => entry[0] + ":" + entry[1])
.join(",");
console.log("prefix=" + prefix);
console.log("names=" + names);
map-entries
`Map.entries()` returns pairs in insertion order. Convert those pairs with `Array.from(...)` when array methods make the next step clearer.