The TypedArray.of() method creates a new typed array with a variable number of arguments. This method is nearly the same as Array.of().

Syntax

TypedArray.of(element0[, element1[, ...[, elementN]]])

where TypedArray is one of:

Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array

Parameters

elementN
Elements of which to create the typed array.

Return value

A new TypedArray instance.

Description

Some subtle distinctions between Array.of() and TypedArray.of():

  • If the 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.

Examples

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 ]

Specifications

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  

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support 45Edge Full support 14Firefox Full support 38IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile ? Firefox Android Full support 38Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs Full support 4.0.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

See also

Document Tags and Contributors

Contributors to this page: fscholz, kdex, nmve, eduardoboucas, jpmedley, cdr
Last updated by: fscholz,