Set.prototype.size

Set 实例的 size 访问器属性返回该集合中(唯一)元素的数量。

¥The size accessor property of Set instances returns the number of (unique) elements in this set.

Try it

描述

¥Description

size 的值是一个整数,表示 Set 对象有多少个条目。size 的设置访问器函数是 undefined;你无法更改此属性。

¥The value of size is an integer representing how many entries the Set object has. A set accessor function for size is undefined; you cannot change this property.

示例

¥Examples

使用尺寸

¥Using size

js
const mySet = new Set();
mySet.add(1);
mySet.add(5);
mySet.add("some text");

console.log(mySet.size); // 3

规范

Specification
ECMAScript Language Specification
# sec-get-set.prototype.size

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also