Baseline Widely available
The TypedArray.of()
static method creates a new typed array from a variable number of arguments. This method is nearly the same as Array.of()
.
const int16array = Int16Array.of("10", "20", "30", "40", "50");
console.log(int16array);
// Expected output: Int16Array [10, 20, 30, 40, 50]
Syntax
TypedArray.of()
TypedArray.of(element1)
TypedArray.of(element1, element2)
TypedArray.of(element1, element2, /* â¦, */ elementN)
Where TypedArray
is one of:
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float16Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array
element1
, â¦, elementN
Elements used to create the typed array.
A new TypedArray
instance.
See Array.of()
for more details. There are some subtle distinctions between Array.of()
and TypedArray.of()
:
this
value passed to TypedArray.of()
is not a constructor, TypedArray.of()
will throw a TypeError
, while Array.of()
defaults to creating a new Array
.TypedArray.of()
uses [[Set]]
while Array.of()
uses [[DefineOwnProperty]]
. Hence, when working with Proxy
objects, it calls handler.set()
to create new elements rather than handler.defineProperty()
.Uint8Array.of(1); // Uint8Array [ 1 ]
Int8Array.of("1", "2", "3"); // Int8Array [ 1, 2, 3 ]
Float32Array.of(1, 2, 3); // Float32Array [ 1, 2, 3 ]
Int16Array.of(undefined); // Int16Array [ 0 ]
Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4