The TypedArray.of()
method creates a new typed array with a variable number of arguments. This method is nearly the same as Array.of()
.
TypedArray.of(element0[, element1[, ...[, elementN]]]) where TypedArray is one of: Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array
elementN
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 [[Put]]
where Array.of
uses [[DefineProperty]]
. 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); // IntArray [ 0 ]
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of '%TypedArray%.of' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262) The definition of '%TypedArray%.of' in that specification. | Draft |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 45 | 14 | 38 | No | No | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | No | No | ? | 38 | No | No | No |
Server | |
---|---|
Node.js | |
Basic support | 4.0.0 |
© 2005–2018 Mozilla Developer Network and individual 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