Standard built-ins

TypedArray.prototype.set()

Try the free JavaScript compiler

Copies values into the target view, converting elements to its numeric type. Throws when the source cannot fit; overlapping typed views are handled.

Formal Syntax & Structure

javascript syntaxjavascript
target.set(source, offset?)

Parameters & Attributes

NameTypeDescription
sourceTypedArray | ArrayLikeValues to copy.
offsetnumberStarting element index; defaults to 0.

Return Value

undefined

Mutates the target view.

Working Example

Example Snippetjavascript
const a=new Uint8Array([1,2,3,4]); a.set(a.subarray(0,3),1); console.log(JSON.stringify([...a]));
JavaScript Reference