Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Set.size Property

Improve Article
Save Article
  • Last Updated : 02 Mar, 2022
Improve Article
Save Article

The Set.size property in JavaScript returns the number of elements in a Set. If the Set is empty the size of the set will be returned as 0.



Here are some examples to illustrate the size property of JavaScript Set object:

Example 1:


    // Create a new set using Set() constructor
    let myset = new Set();
    // Append new elements to the
    // set using add() method
    // Print the modified set
    // As the set has 2 elements,
    // it will return 2.


Set(2) { 23, 12 }

Example 2:


    // Creating a new set
    let myset = new Set();
    // Adding new elements to the set
    // As set has 3 elements, it will return 3



Supported Browsers:

  • Google Chrome:  38+
  • Firefox: 19+
  • Internet Explorer: 11+
  • Opera: 25+
  • Edge: 12+
  • Safari: 08+

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!