The TypedArray.of()
method creates a new typed array from a variable number of arguments. This method is nearly the same as Array.of()
.
The TypedArray.of()
method creates a new typed array from a variable number of arguments. This method is nearly the same as Array.of()
.
TypedArray.of(element0) TypedArray.of(element0, element1) TypedArray.of(element0, element1, /* ... ,*/ elementN)
Where TypedArray
is one of:
elementN
Elements of which to create the typed array.
A new TypedArray
instance.
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
, where Array.of()
defaults to creating a new Array
. TypedArray.of()
uses [[Set]]
where 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 ]
Specification |
---|
ECMAScript Language Specification # sec-%typedarray%.of |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | Deno | Node.js | |
of |
45 |
12 |
38 |
No |
32 |
9.1 |
45 |
45 |
38 |
32 |
9.3 |
5.0 |
1.0 |
4.0.0 |
© 2005–2022 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/of