★ wanayoo — archive 1999 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/setNouvelle recherche | Portail wanayoo

TypedArray.prototype.set()

1 位贡献者:
我们的志愿者还没有将这篇文章翻译为 中文 (简体) 。加入我们帮助完成翻译!

The set() method stores multiple values in the typed array, reading input values from a specified array.

Syntax

typedarr.set(array [,offset])
typedarr.set(typedarray [,offset])

Parameters

array
The array from which to copy values. All values from the source array are copied into the target array, unless the length of the source array plus the offset exceeds the length of the target array, in which case an exception is thrown.
typedarray
If the source array is a typed array, the two arrays may share the same underlying ArrayBuffer; the browser will intelligently copy the source range of the buffer to the destination range.
offset Optional
The offset into the target array at which to begin writing values from the source array. If you omit this value, 0 is assumed (that is, the source array will overwrite values in the target array starting at index 0).

Errors thrown

RangeError
Thrown if the offset is set such as it would store beyond the end of the typed array.

Examples

Using the set method

var buffer = new ArrayBuffer(8);
var uint8 = new Uint8Array(buffer);

uint8.set([1,2,3], 3);

console.log(uint8); // Uint8Array [ 0, 0, 0, 1, 2, 3, 0, 0 ]

Specifications

Specification Status Comment
Typed Array Specification Obsolete Superseded by ECMAScript 6.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'TypedArray.prototype.set' in that specification.
Standard Initial definition in an ECMA standard.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 7.0 4.0 (2) 10 11.6 5.1
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 4.0 (Yes) 4.0 (2) 10 11.6 4.2

See also

文档标签和贡献者

向此页面作出贡献: fscholz
最后编辑者: fscholz,
隐藏侧边栏