Int16Array.of(10, -20, 30) creates a new typed array whose elements are exactly the arguments you pass. It is a static method of the hidden TypedArray parent class, so you call it on a real type such as Int16Array or Uint8Array. Every argument is converted to the element type, so out-of-range numbers wrap around. The big difference from the constructor: Uint8Array.of(3) makes one element with the value 3, but new Uint8Array(3) makes three zeros.
The constructor sees a size.new Uint8Array(3) reserves three bytes that start as zero.
of() sees a value.Uint8Array.of(3) stores the number 3 as the only element, so its length is 1.
Spread, empty, and BigInt. Spread passes an array as separate arguments, no arguments gives length 0, and a BigInt array accepts only BigInt arguments.
Compatibility
Browser & Runtime Support
TypedArray.of() is part of ES2015 (ES6), the same edition that added the static from() method and the typed array methods.
✓ Baseline · ES2015
TypedArray.of()
Supported in every modern browser, plus Node.js, Deno, and Bun.
98%Modern browser support
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
Node.jsAll current releases
Supported
DenoAll releases
Supported
Internet ExplorerIE 10 and 11 have typed arrays, but not this method
Not supported
TypedArray.of()Excellent
Bottom line: Safe everywhere modern JavaScript runs. Internet Explorer 10 and 11 have typed arrays, but not the static of() method.
Frequently Asked Questions
It creates a new typed array of the type you call it on, using its arguments as the elements. Int16Array.of(1, 2, 3) returns an Int16Array with three elements.
Because of() always treats arguments as values. Only the constructor treats a single number as the length. Use new Uint8Array(3) for three zeros.
Use the spread syntax: Uint8Array.of(...list). If you already have an array, Uint8Array.from(list) or new Uint8Array(list) is simpler.
They wrap to fit the type. Uint8Array.of(256) is 0 and Int8Array.of(128) is -128. A Uint8ClampedArray clamps to 0 and 255 instead.
Yes, but every argument must be a BigInt such as 1n. Passing a normal number throws a TypeError.