TypedArray Methods (ECMAScript 2015) Sample

Available in Chrome 45+ | View on GitHub | Browse Samples

ECMAScript 2015 specification adds additional static methods on TypedArray subclasses (Int8Array, Float32Array, ...) and instance methods on their prototype that mirror most Array.prototype methods.

TypedArray.from ( items [ , mapfn [ , thisArg ] ] ) #

The TypedArray.from() method creates a new way to make TypedArrays based on existing iterable or Array-like objects, analogous to Array.from.

Uint8Array.from(new Set([1, 1, 2, 3]));         // [1, 2, 3]
Uint8Array.from('hello');                       // [0, 0, 0, 0, 0]
Uint8Array.from('hello', x => x.charCodeAt(0)); // [104, 101, 108, 108, 111]

TypedArray.of ( ...items ) #

The TypedArray.of() method is almost the same as Array.of().

Uint8Array.of(1, 2, 3, 256 + 4); // [1, 2, 3, 4]

Additional mirrored Array.prototype instance methods