blob: 9ff986da31711d92ed8a5f4a2c78f28e9c3c77b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
---
title: Set.prototype.size
slug: Web/JavaScript/Reference/Global_Objects/Set/size
tags:
- ECMAScript 2015
- JavaScript
- Property
- set
translation_of: Web/JavaScript/Reference/Global_Objects/Set/size
---
<div>{{JSRef}}</div>
<p><strong>Size</strong>属性将会返回{{jsxref("Set")}}对象中元素的个数。</p>
<p>{{EmbedInteractiveExample("pages/js/set-prototype-size.html")}}</p>
<h2 id="描述">描述</h2>
<p><code>size</code>的值是一个整数,表示<code>Set</code>对象有多少条目。<code>size</code>的集合访问函数是<code>undefined</code>; 你不能改变这个属性。</p>
<h2 id="例子">例子</h2>
<h3 id="使用size">使用<code>size</code></h3>
<pre class="brush:js">var mySet = new Set();
mySet.add(1);
mySet.add(5);
mySet.add("some text")
mySet.size; // 3
</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>
<p>{{SpecName('ES6', '#sec-get-set.prototype.size', 'Set.prototype.size')}}</p>
</td>
<td>{{Spec2('ES6')}}</td>
<td>初始定义</td>
</tr>
<tr>
<td>
<p>{{SpecName('ESDraft', '#sec-get-set.prototype.size', 'Set.prototype.size')}}</p>
</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容">浏览器兼容</h2>
<p>{{Compat("javascript.builtins.Set.size")}}</p>
<h2 id="参见">参见</h2>
<ul>
<li>{{jsxref("Set")}}</li>
</ul>
|