I was reading in MDN about TypedArray and saw that several classes derive from this.
Classes that are derived from TypeArray
:
- Int8Array
- Uint8Array
- Uint8ClampedArray
- Int16Array
- Uint16Array
- Int32Array
- Uint32Array
- Float32Array
- Float64Array
As I understand it, each of these "arrays" accept a different type of input.
A test with Int8Array
:
var arr = new Int8Array(4);
arr[0] = 1;
arr[1] = 2;
arr[2] = 2.5;
arr[3] = "X2.5";
console.log(arr, arr.constructor.name);
In the above case, 2.5
as the value string
, were converted to int
.
Given that these arrays
have this type of behavior, I would like to ask some questions:
-
In what cases should I use
TypedArray
instead of% defaultArray
of Javascript? I would like examples -
Is there any performance gain when using
TypedArray
instead of usingArray
? -
I'd like to know about the compatibility and polyfills about the same.