diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/global_objects/uint16array | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/uint16array')
-rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/uint16array/index.html | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/uint16array/index.html b/files/zh-cn/web/javascript/reference/global_objects/uint16array/index.html new file mode 100644 index 0000000000..6d7fadd8e9 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/uint16array/index.html @@ -0,0 +1,160 @@ +--- +title: Uint16Array +slug: Web/JavaScript/Reference/Global_Objects/Uint16Array +translation_of: Web/JavaScript/Reference/Global_Objects/Uint16Array +--- +<div>{{JSRef}}</div> + +<p><code><font face="Arial, x-locale-body, sans-serif"><span style="background-color: #ffffff;">该 </span></font><strong>Uint16Array</strong></code> 类型数组表示16位无符号整数,按平台字节顺序排列。如果需要控制字节顺序,请使用 DataView 代替。内容被初始化为0。建立后,就可以使用对象的方法或使用标准数组索引语法(即使用括号表示法)引用数组中的元素。</p> + +<h2 id="构造函数">构造函数</h2> + +<dl> + <dt><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array/Uint16Array"><code>Uint16Array()</code></a></dt> + <dd>创建一个新的 <code>Uint16Array</code> 对象。</dd> +</dl> + +<h2 id="静态属性">静态属性</h2> + +<dl> + <dt>{{jsxref("TypedArray.BYTES_PER_ELEMENT", "Uint16Array.BYTES_PER_ELEMENT")}}</dt> + <dd>返回元素大小的数值。在 <code>Uint16Array</code> 情况下为 <code>2</code>。</dd> + <dt>{{jsxref("TypedArray.name", "Uint16Array.name")}}</dt> + <dd>返回构造函数名称的字符串值。 在 <code>Uint16Array</code> 情况下,类型为: "Uint16Array"。</dd> +</dl> + +<h2 id="静态方法">静态方法</h2> + +<dl> + <dt>{{jsxref("TypedArray.from", "Uint16Array.from()")}}</dt> + <dd>从类数组或可迭代对象创建一个新的 <code>Uint16Array</code> 。可参阅 {{jsxref("Array.from()")}}。</dd> + <dt>{{jsxref("TypedArray.of", "Uint16Array.of()")}}</dt> + <dd>创建一个新的具有可变参数数目的 <code>Uint16Array</code> 。可参阅 {{jsxref("Array.of()")}}。</dd> +</dl> + +<h2 id="实例属性">实例属性</h2> + +<dl> + <dt>{{jsxref("TypedArray.prototype.buffer", "Uint16Array.prototype.buffer")}}</dt> + <dd>返回 <code>Uint16Array</code> 在构造时固定引用的 {{jsxref("ArrayBuffer")}} 。因此是 <strong>只读的</strong>。</dd> + <dt>{{jsxref("TypedArray.prototype.byteLength", "Uint16Array.prototype.byteLength")}}</dt> + <dd>返回 <code>Uint16Array</code> 从 {{jsxref("ArrayBuffer")}}开始的长度(以字节为单位)。在构建时固定,因此是 <strong>只读的 。</strong></dd> + <dt>{{jsxref("TypedArray.prototype.byteOffset", "Uint16Array.prototype.byteOffset")}}</dt> + <dd>返回 <code>Uint16Array</code> 从 {{jsxref("ArrayBuffer")}}开始的偏移量(以字节为单位)。在构建时固定,因此是 <strong>只读的 。</strong></dd> + <dt>{{jsxref("TypedArray.prototype.length", "Uint16Array.prototype.length")}}</dt> + <dd>返回 <code>Uint16Array</code> 中包含的元素数量。在构建时固定,因此是 <strong>只读的 。</strong></dd> +</dl> + +<h2 id="实例方法">实例方法</h2> + +<dl> + <dt>{{jsxref("TypedArray.copyWithin", "Uint16Array.prototype.copyWithin()")}}</dt> + <dd>复制数组中的一序列数组元素。 可参阅 {{jsxref("Array.prototype.copyWithin()")}}。</dd> + <dt>{{jsxref("TypedArray.entries", "Uint16Array.prototype.entries()")}}</dt> + <dd>返回一个新的 <code>Array Iterator</code> 对象,该对象包含数组中的每个索引的键/值对。可参阅 {{jsxref("Array.prototype.entries()")}}。</dd> + <dt>{{jsxref("TypedArray.every", "Uint16Array.prototype.every()")}}</dt> + <dd>测试数组中的所有元素是否通过函数提供的测试。 可参阅 {{jsxref("Array.prototype.every()")}}。</dd> + <dt>{{jsxref("TypedArray.fill", "Uint16Array.prototype.fill()")}}</dt> + <dd>使用静态值填充从开始索引到结束索引的数组的所有元素。 可参阅 {{jsxref("Array.prototype.fill()")}}。</dd> + <dt>{{jsxref("TypedArray.filter", "Uint16Array.prototype.filter()")}}</dt> + <dd>根据所提供的过滤函数,将所有返回true的所有元素创建一个新的数组。可参阅 {{jsxref("Array.prototype.filter()")}}。</dd> + <dt>{{jsxref("TypedArray.find", "Uint16Array.prototype.find()")}}</dt> + <dd>返回数组中满足所提供的测试函数的值,没有则返回 <code>undefined</code> 。 可参阅 {{jsxref("Array.prototype.find()")}}。</dd> + <dt>{{jsxref("TypedArray.findIndex", "Uint16Array.prototype.findIndex()")}}</dt> + <dd>返回数组中满足所提供的测试函数的索引,没有则返回 -1。 可参阅 {{jsxref("Array.prototype.findIndex()")}}。</dd> + <dt>{{jsxref("TypedArray.forEach", "Uint16Array.prototype.forEach()")}}</dt> + <dd>为数组中的每个元素调用一个函数。 可参阅 {{jsxref("Array.prototype.forEach()")}}。</dd> + <dt>{{jsxref("TypedArray.includes", "Uint16Array.prototype.includes()")}}</dt> + <dd>判断数组中是否包含某个元素,有则返回 <code>true</code> ,无则返回 <code>false</code> 。 可参阅 {{jsxref("Array.prototype.includes()")}}。</dd> + <dt>{{jsxref("TypedArray.indexOf", "Uint16Array.prototype.indexOf()")}}</dt> + <dd>返回数组中等于指定的值的元素第一个(最小)索引,没有则返回 -1。 可参阅 {{jsxref("Array.prototype.indexOf()")}}。</dd> + <dt>{{jsxref("TypedArray.join", "Uint16Array.prototype.join()")}}</dt> + <dd>将数组中的所有元素连接成字符串。可参阅 {{jsxref("Array.prototype.join()")}}。</dd> + <dt>{{jsxref("TypedArray.keys", "Uint16Array.prototype.keys()")}}</dt> + <dd>f返回一个新的 <code>Array Iterator</code> ,其包含数组中每个索引的键。 可参阅 {{jsxref("Array.prototype.keys()")}}。</dd> + <dt>{{jsxref("TypedArray.lastIndexOf", "Uint16Array.prototype.lastIndexOf()")}}</dt> + <dd>返回数组中最后一个(最大的)与指定值相等的元素的索引,没有则返回 -1。可参阅 {{jsxref("Array.prototype.lastIndexOf()")}}。</dd> + <dt>{{jsxref("TypedArray.map", "Uint16Array.prototype.map()")}}</dt> + <dd>返回一个根据所提供的函数对每个元素处理后的新数组。可参阅 {{jsxref("Array.prototype.map()")}}。</dd> + <dt>{{jsxref("TypedArray.reduce", "Uint16Array.prototype.reduce()")}}</dt> + <dd>根据所提供的函数对累加器和数组的每一个值(从左到右)进行处理,并返回最后调用函数的值。可参阅 {{jsxref("Array.prototype.reduce()")}}。</dd> + <dt>{{jsxref("TypedArray.reduceRight", "Uint16Array.prototype.reduceRight()")}}</dt> + <dd>根据所提供的函数对累加器和数组的每一个值(从右到左)进行处理,并返回最后调用函数的值。 可参阅 {{jsxref("Array.prototype.reduceRight()")}}。</dd> + <dt>{{jsxref("TypedArray.reverse", "Uint16Array.prototype.reverse()")}}</dt> + <dd>颠倒数组的顺序,使第一个元素成为最后一个,最后一个元素成为第一个。 可参阅 {{jsxref("Array.prototype.reverse()")}}。</dd> + <dt>{{jsxref("TypedArray.set", "Uint16Array.prototype.set()")}}</dt> + <dd>在类型化数组中存储多个值,从指定数组中读取输入值。</dd> + <dt>{{jsxref("TypedArray.slice", "Uint16Array.prototype.slice()")}}</dt> + <dd>截取数组中的一部分并作为新数组返回。 可参阅 {{jsxref("Array.prototype.slice()")}}。</dd> + <dt>{{jsxref("TypedArray.some", "Uint16Array.prototype.some()")}}</dt> + <dd>判读数组中是否至少有一个元素满足所提供的测试函数,有则返回 true。 可参阅 {{jsxref("Array.prototype.some()")}}。</dd> + <dt>{{jsxref("TypedArray.sort", "Uint16Array.prototype.sort()")}}</dt> + <dd>对数组中的元素进行排序并返回排序后的数组。 可参阅 {{jsxref("Array.prototype.sort()")}}。</dd> + <dt>{{jsxref("TypedArray.subarray", "Uint16Array.prototype.subarray()")}}</dt> + <dd>从给定的开始与结束元素索引中返回一个新的 <code>Uint16Array</code> 。</dd> + <dt>{{jsxref("TypedArray.values", "Uint16Array.prototype.values()")}}</dt> + <dd>返回一个新的 <code>Array Iterator</code> 对象,该对象包含数组中的每个索引的值。 可参阅 {{jsxref("Array.prototype.values()")}}.</dd> + <dt>{{jsxref("TypedArray.toLocaleString", "Uint16Array.prototype.toLocaleString()")}}</dt> + <dd>返回表示数组及其元素的本地化字符串。 可参阅 {{jsxref("Array.prototype.toLocaleString()")}}。</dd> + <dt>{{jsxref("TypedArray.toString", "Uint16Array.prototype.toString()")}}</dt> + <dd>返回表示数组及其元素的字符串。可参阅 {{jsxref("Array.prototype.toString()")}}。</dd> + <dt>{{jsxref("TypedArray.@@iterator", "Uint16Array.prototype[@@iterator]()")}}</dt> + <dd>返回一个新的 <code>Array Iterator</code> 对象, 其包含数组中每个索引的值。</dd> +</dl> + +<h2 id="示例">示例</h2> + +<h3 id="Different_ways_to_create_a_Uint16Array">Different ways to create a Uint16Array</h3> + +<pre class="brush: js notranslate">// 长度 +var uint16 = new Uint16Array(2); +uint16[0] = 42; +console.log(uint16[0]); // 42 +console.log(uint16.length); // 2 +console.log(uint16.BYTES_PER_ELEMENT); // 2 + +// 数组 +var arr = new Uint16Array([21,31]); +console.log(arr[1]); // 31 + +// 另一个类型数组 +var x = new Uint16Array([21, 31]); +var y = new Uint16Array(x); +console.log(y[0]); // 21 + +// 一个 ArrayBuffer +var buffer = new ArrayBuffer(8); +var z = new Uint16Array(buffer, 0, 4); + +// 可迭代 +var iterable = function*(){ yield* [1,2,3]; }(); +var uint16 = new Uint16Array(iterable); +// Uint16Array[1, 2, 3] +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#table-49', 'TypedArray constructors')}}</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div class="hidden">此页面上的兼容性表是由结构化数据生成的。如果您想贡献数据,请查看 <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并向我们发送pull请求。</div> + +<p>{{Compat("javascript.builtins.Uint16Array")}}</p> + +<h2 id="可参阅">可参阅</h2> + +<ul> + <li><a href="/en-US/docs/Web/JavaScript/Typed_arrays" title="en/JavaScript typed arrays">JavaScript typed arrays</a></li> + <li>{{jsxref("ArrayBuffer")}}</li> + <li>{{jsxref("DataView")}}</li> +</ul> |