• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • VBA
  • About
You are here: Home / JavaScript / JavaScript Map Size – Find Length of JavaScript Map

JavaScript Map Size – Find Length of JavaScript Map

January 24, 2022 Leave a Comment

In JavaScript, we can easily find the size of a map using the map size property on a map object.

map.size;

In JavaScript, the map object is useful for holding key-value pairs.

When working with objects in JavaScript, the ability to get the size or length of an object can be useful for use in loops.

To get the length of a map in JavaScript, we can use the map size property. The JavaScript map size property is read only and returns an integer value.

Let’s say we have the following JavaScript map.

var map = new Map();
map.set('Apple','Good');
map.set('Pear','No');
map.set('Banana','Maybe');
map.set('Lemon','Yes');

To get the size of the map, we use the JavaScript map size property.

console.log(map.size);

// Output:
4

Something to note here is that the map object does not have a ‘length’ property. If you try to access the ‘length’ property of a map object, you will get ‘undefined’.

console.log(map.length);

// Output:
undefined

Hopefully this article has been useful for you to understand how to get the size of a JavaScript Map.

Other Articles You'll Also Like:

  • 1.  Using JavaScript to Remove the Last Character From a String
  • 2.  Changing the Background Image of a div in JavaScript
  • 3.  Clicking on an Image to Enlarge it in HTML
  • 4.  How to Return Multiple Values in JavaScript
  • 5.  How to Repeat Character N Times in JavaScript
  • 6.  Using the appendChild Method with JavaScript to Add Items to a List
  • 7.  Grouping By Multiple Properties and Summing Using Javascript
  • 8.  charAt() JavaScript – Getting the Index Position of a Character
  • 9.  JavaScript substring – How to Get a Substring From a String
  • 10.  How to Hide a Div in JavaScript

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2022 · The Programming Expert · About · Privacy Policy