• 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
  • Ruby
  • 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 Check if Variable is an Object
  • 2.  parseInt() JavaScript – Convert String to Integer with parseInt() method
  • 3.  Using JavaScript to Get the URL Path
  • 4.  Uncheck a Radio Button Using JavaScript
  • 5.  Using JavaScript to Get the Host URL
  • 6.  Using JavaScript to Scroll to the Top of the Page
  • 7.  Using JavaScript to Set Select to the First Option
  • 8.  Using JavaScript to Format the Date in mm dd yyyy
  • 9.  lastIndexOf JavaScript – Get the Last Position of a String in Another String
  • 10.  Using JavaScript to Check a Radio Button

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

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

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 © 2023 · The Programming Expert · About · Privacy Policy