size accessor property returns the number of (unique) elements in a Set 对象。

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

描述

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.

范例

使用 size

var mySet = new Set();
mySet.add(1);
mySet.add(5);
mySet.add('some text')
mySet.size; // 3
					

规范

规范
ECMAScript (ECMA-262)
The definition of 'Set.prototype.size' in that specification.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
size Chrome 38 Edge 12 Firefox 19
19
From Firefox 13 to Firefox 18, the size property was implemented as a Set.prototype.size() method, this has been changed to a property in later versions conform to the ECMAScript 2015 specification.
IE 11 Opera 25 Safari 8 WebView Android 38 Chrome Android 38 Firefox Android 19
19
From Firefox 13 to Firefox 18, the size property was implemented as a Set.prototype.size() method, this has been changed to a property in later versions conform to the ECMAScript 2015 specification.
Opera Android 25 Safari iOS 8 Samsung Internet Android 3.0 nodejs 0.12

图例

完整支持

完整支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: