Uint8Array.from(source) builds a new typed array from an array, an array-like object, or any iterable such as a Set or a string. It is a static method of the hidden TypedArray parent class, so you call it on a real type like Int16Array. The optional second argument is a map function that changes each value on its way in. Its result is converted to the element type.
Remember
Uint8Array.from(source) → new typed array
Uint8Array.from(source, mapFn) → convert each value first
Uint8Array.from(source, mapFn, thisArg)
from: array, Set, string, { length: 3, 0: .. }
mapFn(value, index) → result is wrapped to the type
Uint8Array.from([1, 2, 3], n => n * 100) → 100 200 44
Syntax
Call from() on a concrete typed array type. Only the source is required.
Turn any iterable, like a Set, into a typed array.
Float32Array.from(src, (v) => v * 2)
Change every value while building.
Static method, available since ES2015 on all 11 typed array types.
Library declarations
JavaScript
TypedArray.from(source)
TypedArray.from(source, mapFn)
TypedArray.from(source, mapFn, thisArg)
// mapFn(value, index) -> any value, converted to the element type
// "this" must be a typed array constructor, otherwise: TypeError
Parameters
Parameter
Description
source
An array, array-like object (with length), or iterable. Missing items become 0 in an integer array.
mapFn (optional)
A function (value, index) called for every item. Its return value is stored after conversion to the element type.
thisArg (optional)
The value used as this when mapFn runs. Arrow functions ignore it.
Return Value
Return Value
Description
TypedArray
A new typed array of the type you called it on. A BigInt array needs BigInt values, or a TypeError is thrown.
JavaScript Examples
Example 1 — Build From Different Sources
The same call accepts an array, a Set, an array-like object, and a string. Each one ends up as a Uint8Array.
Decimals are cut, text is parsed. The Int16Array drops the fraction of 1.9 and -2.9 (toward zero) and reads "7" as the number 7.
BigInt arrays take BigInt.BigInt64Array.from([10n, 20n]) works, and String() prints the BigInt without an n.
Three ways to get a TypeError. A loose copy of the function has no this, a plain object is not a constructor, and numbers cannot go into a BigInt array.
Compatibility
Browser & Runtime Support
TypedArray.from() is part of ES2015 (ES6), the same edition that introduced typed array methods, Set, and iterables.
✓ Baseline · ES2015
TypedArray.from()
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.from()Excellent
Bottom line: Safe everywhere modern JavaScript runs. Internet Explorer 10 and 11 have typed arrays, but not the static from() method.
Frequently Asked Questions
It creates a new typed array of the type you call it on, with one element per item of an array, iterable, or array-like object.
TypedArray is only the hidden parent class. You call from() on a real type such as Uint8Array, and that type decides how values are stored.
The constructor just copies numbers. from() also accepts a map function, a thisArg, and Set or string sources.
They wrap: Uint8Array.from([300]) stores 44, and Uint8ClampedArray.from([300]) stores 255. Nothing throws.
Almost, but the result is a typed array, not a regular Array. Array.from(typedArray) goes the other way.