What methods are in typed arrays?
It’s much more pleasant to use it now than ever.
from static method lets us convert an array-like or iterable object into a typed array.
The first argument is the iterable object we want to convert to a typed array.
The 2nd is a callback that has the value of the entry and the index as the parameter of the array to let us return something we want.
The 3rd argument is the value of
this we want to have in the callback in the 2nd argument.
The 2nd and 3rd arguments are optional.
For example, we can write:
const typedArr = Uint16Array.from([0, 1, 2]);
We pass in the array value and returns a
Uint16Array with the entries from the array.
The callback for mapping the entries let us create a new array that doesn’t overflow rather than have them overflow.
For example, instead of writing:
const arr = Int8Array.of(200, 201, 202).map(x => 2 * x)
And get the
Int8Array with values
[-112, -110, -108] .
We can write:
const arr = Int32Array.from(Int8Array.of(120, 121, 122), x => x * 2)
[240, 242, 244] in an