Example 1 — Remove One Entry
Delete a score by name, then check that it is gone while another score stays.
const scores = new Map();
scores.set("Ann", 10);
scores.set("Bob", 8);
console.log(scores.delete("Ann")); // true
console.log(String(scores.get("Ann"))); // undefined
console.log(scores.get("Bob")); // 8 How It Works
- The first delete finds the entry.
scores.delete("Ann")removes Ann and reports it withtrue. - The entry is really gone. Right after the removal,
get("Ann")answersundefined. - Other keys stay. Bob was never deleted, so
get("Bob")still returns 8.

