JavaScript size

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

map.size is the number of key/value pairs in a Map. It updates as you set and delete.

JavaScript Syntax

JavaScript
const m = new Map();
m.set("a", 1);
m.set("b", 2);
console.log(m.size);
m.delete("a");
console.log(m.size);
Try it Editor

How It Works

  1. set. Adds entries.
  2. size. Counts them.
  3. delete. size shrinks.

Examples

Example 1 — Empty map

Starts at 0.

JavaScript
console.log(new Map().size);
Try it Editor

How It Works

  1. No entries yet.

Frequently Asked Questions

No—use size.
No—it is read-only.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful