Example 1 — Empty map
Starts at 0.
JavaScript
console.log(new Map().size);How It Works
- No entries yet.
map.size is the number of key/value pairs in a Map. It updates as you set and delete.
const m = new Map();
m.set("a", 1);
m.set("b", 2);
console.log(m.size);
m.delete("a");
console.log(m.size);Starts at 0.
console.log(new Map().size);CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful