53 lines
2.8 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<article id="wikiArticle">
<div><br/>
 </div>
<p><code><strong>size</strong></code> 是可访问属性,用于返回 一个<a href="Reference/Map" title="此页面仍未被本地化, 期待您的翻译!"><code>Map</code></a> 对象的成员数量。</p>
<p><iframe class="interactive interactive-js" frameborder="0" height="250" src="https://interactive-examples.mdn.mozilla.net/pages/js/map-prototype-size.html" width="100%"></iframe></p>
<p>这个示例源码保存在GitHub<a class="external" href="https://github.com/mdn/interactive-examples" rel="noopener">https://github.com/mdn/interactive-examples</a>。如果你想贡献代码修改后在GitHub上发推送请求给我们。</p>
<p> </p>
<h2 id="描述">描述</h2>
<p>size 属性的值是一个整数,表示 Map 对象有多少个键值对。size 是只读属性用set 方法修改size返回 undefined即不能改变它的值。</p>
<h2 id="示例">示例</h2>
<pre><code class="language-js">var myMap = new Map();
myMap.set("a", "alpha");
myMap.set("b", "beta");
myMap.set("g", "gamma");
myMap.size // 3
</code></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><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-get-map.prototype.size" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">Map.prototype.size</small></a></td>
<td><span class="spec-Standard">Standard</span></td>
<td>Initial definition.</td>
</tr>
<tr>
<td><a class="external" href="https://tc39.github.io/ecma262/#sec-get-map.prototype.size" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">Map.prototype.size</small></a></td>
<td><span class="spec-Draft">Draft</span></td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容">浏览器兼容</h2>
<p>此页的兼容性表格请查阅:<a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">https://github.com/mdn/browser-compat-data</a> <br/>
如果你想更新数据请在GitHub上给我们发推送请求。</p>
<div class="blockIndicator warning">
<p><strong>异常提醒</strong></p>
</div>
<ul>
<li>在JavaScript中直接书写Map.prototype.size可能得到以下异常<br/>
<code>Uncaught TypeError: Method get Map.prototype.size called on incompatible receiver #&lt;Map&gt;</code><br/>
异常原因查看:<a class="new" href="/zh-CN/docs/" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Called_on_incompatible_type</a></li>
</ul>
<h2 id="相关阅读">相关阅读</h2>
<ul>
<li><a href="Reference/Map" title="此页面仍未被本地化, 期待您的翻译!"><code>Map</code></a></li>
</ul>
</article>