Skip to content

JavaScript Set size | Accessor property

  • by

Use the JavaScript Set size property to get the number of elements in a Set object. The size property returns the number of values in the Set object.


As opposed to the array’s length property, the size property is read-only and can’t be changed by the user.

JavaScript Set size

Simple example code.

<!DOCTYPE html>
    const set1 = new Set([1,2,3,4]);

    console.log("size", set1.size);



JavaScript Set size property

More examples

const set1 = new Set();
const object1 = {};

set1.add('forty two');
set1.add('forty two');

console.log(set1.size); // 3
const set = new Set(['a', 'b', 'c']);

console.log(set.size); // 👉️ 3


console.log(set.size); // 👉️ 5

Do comment if you have any doubts or suggestions on this Js set property topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

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