---
title: SharedArrayBuffer.prototype.byteLength
slug: Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength
tags:
  - SharedArrayBuffer
translation_of: Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer/byteLength
---
<div>{{JSRef}}</div>

<p> <code><strong>byteLength</strong></code> 访问器属性表示以字节为单位的一个{{jsxref("SharedArrayBuffer")}}的长度。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><var>sab</var>.byteLength</pre>

<h2 id="描述">描述</h2>

<p><code>byteLength</code>属性是一个访问者属性,其set访问者函数为 <code>undefined</code>,这意味着您只能读取此属性。 该值在构造共享数组时建立,并且无法更改。</p>

<h2 id="例子">例子</h2>

<pre class="brush:js">var sab = new SharedArrayBuffer(1024);
sab.byteLength; // 1024
</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>{{SpecName('ESDraft', '#sec-get-sharedarraybuffer.prototype.bytelength', 'SharedArrayBuffer.prototype.byteLength')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td>Initial definition in ES2017.</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>



<p>{{Compat("javascript.builtins.SharedArrayBuffer.byteLength")}}</p>

<h2 id="相关链接">相关链接</h2>

<ul>
 <li>{{jsxref("SharedArrayBuffer")}}</li>
</ul>