| description | An Array-like view on a raw binary buffer. |
|---|
An Array-like view on a raw binary buffer.
The TypedArray API works very much like JavaScript's (MDN). The name TypedArray below represents one of the variants of element type T and is not an actual class. Note that typed arrays are not actually generic, but concrete implementations like Uint8Array and Float64Array have an identical interface that only differs in the implementation's element type denoted as T.
| Variant | Element type | Description |
|---|---|---|
| Int8Array | i8 | A view on 8-bit signed integer values. |
| Int16Array | i16 | A view on 16-bit signed integer values. |
| Int32Array | i32 | A view on 32-bit signed integer values. |
| Int64Array | i64 | A view on 64-bit signed integer values. |
| Uint8Array | u8 | A view on 8-bit unsigned integer values. |
| Uint8ClampedArray | u8 | A view on 8-bit unsigned integer values, with set values clamped between 0 and 255 inclusive. |
| Uint16Array | u16 | A view on 16-bit unsigned integer values. |
| Uint32Array | u32 | A view on 32-bit unsigned integer values. |
| Uint64Array | u64 | A view on 64-bit unsigned integer values. |
| Float32Array | f32 | A view on 32-bit float values. |
| Float64Array | f64 | A view on 64-bit float values. |
-
Constructs a new typed array view with a new backing buffer and all values initialized to zero. See
new TypedArray(length: i32)
wrapbelow for wrapping a raw buffer.
-
const BYTES_PER_ELEMENT: usize
Number of bytes per element.
-
function wrap(buffer: ArrayBuffer, byteOffset?: i32, length?: i32): TypedArray
Wraps a raw buffer to be viewed as a sequence of values of the typed array's value type. This is equivalent to the respective alternative constructor signature in JS but exists because there is no function overloading (yet).
-
readonly buffer: ArrayBuffer
The backing array buffer of this view.
-
readonly byteOffset: i32
The offset in bytes from the start of the backing buffer.
-
readonly byteLength: i32
The length in bytes from the start of the backing buffer.
-
readonly length: i32
The length in elements.
-
function every(fn: (value: T, index: i32, self: TypedArray) => bool): bool
Calls the specified function with every value of the array until it finds the first value for which the function returns
false. Returnstrueif all functions returnedtrueor the array is empty, otherwisefalse. -
function fill(value: T, start?: i32, end?: i32): this
Replaces the values of the array from
startinclusive toendexclusive in place with the specified value, returning the array. -
function findIndex(fn: (value: T, index: i32, self: TypedArray) => bool): i32
Calls the specified function with every value of the array until it finds the first value for which the function returns
true, returning its index. Returns-1if that's never the case. -
function findLastIndex(fn: (value: T, index: i32, self: TypedArray) => bool): i32
Calls the specified function with every value of the array starting at the end until it finds the first value for which the function returns
true, returning its index. Returns-1if that's never the case. -
function forEach(fn: (value: T, index: i32, self: TypedArray) => void): void
Calls the specified function with every value of the array.
-
function includes(value: T, fromIndex?: i32): bool
Tests if the array includes the specified value, optionally providing a starting index.
-
function indexOf(value: T, fromIndex?: i32): i32
Gets the first index where the specified value can be found in the array. Returns
-1if not found. -
function lastIndexOf(value: T, fromIndex?: i32): i32
Gets the last index where the specified value can be found in the array. Returns
-1if not found. -
function map(fn: (value: T, index: i32, self: TypedArray) => T): TypedArray
Calls the specified function with every value of the array, returning a new array of the function's return values.
-
function reduce<U>( fn: (accumValue: U, currentValue T, index: i32, self: TypedArray) => U, initialValue: U ): U
Calls the specified reducer function with each value of the array, resulting in a single return value. The respective previous reducer function's return value is remembered in
accumValue, starting withinitialValue, becoming the final return value in the process. -
function reduceRight<U>( fn: (accumValue: U, currentValue: T, index: i32, self: TypedArray) => U, initialValue: U ): U
Calls the specified reducer function with each value of the array, from right to left, resulting in a single return value.
-
function reverse(): this
Reverses an array's values in place, modifying the array before returning it.
-
function set(source: ArrayLike<number>, offset?: i32): void
Sets the typed array values (starting at
offset, or 0), reading input values from a specifiedsourcearray. -
function some(fn: (value: T, index: i32, self: TypedArray) => bool): bool
Calls the specified function with every value of the array until it finds the first value for which the function returns
true, returningtrue. Returnsfalseotherwise or if the array is empty. -
function sort(fn: (a: T, b: T) => i32): this
Sorts the values of the array in place, using the specified comparator function, modifying the array before returning it. The comparator returning a negative value means
a < b, a positive value meansa > band0means that both are equal. Unlike in JavaScript, where an implicit conversion to strings is performed, the comparator defaults to compare two values of typeT. -
function subarray(start?: i32, end?: i32): TypedArray
Returns a new view on the array's backing buffer from
begininclusive toendexclusive relative to this array. If omitted,enddefaults to the end of the array. Does not copy.