What is a typed array ?
Typed array is an ArrayBufferView that interprets the bytes present in the ArrayBuffer as array of numbers.
This also allows the read and write access to the elements of the array.
What is a typed array in javascript ?
Typed arrays are like objects also provides accessing raw binary data.
These Array objects can also have javascript values assigned dynamically.
JavaScript engines perform optimizations so that these arrays are fast.
This is most useful in manipulating raw binary data into typed arrays.
Javascript advanced course !!!
Click to Learn More about – Javascript online learning
Here is some of the types of Typed Arrays,
Sno | Typed Array | Value Range | Size in Bytes | Description | Web IDL Type |
---|---|---|---|---|---|
1 | Int8Array | -128 to 127 | 1 | 8-bit two’s complement signed integer | byte |
2 | Uint8Array | 0 to 255 | 1 | 8-bit unsigned integer | octet |
3 | Uint8ClampedArray | 0 to 255 | 1 | 8-bit unsigned integer (clamped) | octet |
4 | Int16Array | -32768 to 32767 | 2 | 16-bit two’s complement signed integer | short |
5 | Uint16Array | 0 to 65535 | 2 | 16-bit unsigned integer unsigned | short |
6 | Int32Array | -2147483648 to 2147483647 | 4 | 32-bit two’s complement signed integer | long |
7 | Uint32Array | 0 to 4294967295 | 4 | 32-bit unsigned integer unsigned | long |
8 | Float32Array | 1.2×10-38 to 3.4×1038 | 4 | 32-bit IEEE floating point number ( 7 significant digits e.g. 1.1234567) | unrestricted float |
9 | Float64Array | 5.0×10-324 to 1.8×10308 | 8 | 64-bit IEEE floating point number (16 significant digits e.g. 1.123…15) | unrestricted float |
10 | BigInt64Array | -263 to 263-1 | 8 | 64-bit two’s complement signed integer | bigint |
11 | BigUint64Array | 0 to 264-1 | 8 | 64-bit unsigned integer | bigint |
Typed array methods in Javascript
Here is some of the Methods in Typed Arrays,
Sno | Methods | Description |
---|---|---|
1 | copyWithin() | copyWithin () method copies a portion of an array to another location in the same array and returns the size without modification. |
2 | entries() | entries() method returns a new Array Iterator object that contains key/value pairs for each index in the array. |
3 | every() | every() method tests whether all the elements of the array satisfy the given condition or not. |
4 | fill() | fill() method is used to fill all the elements of array from a start index to an end index with a static value. |
5 | filter() | filter() method forms a new array that falls under a given criteria from an existing array. |
6 | find() | find() Method is used to get the value of the first element in the array that satisfies the provided condition. |
7 | findIndex() | findIndex() method is used to provide the index of the element that complete the given test in the array. |
8 | forEach() | forEach() method calls the provided function once for each element of the array. |
9 | includes() | includes() method is used to determine whether a particular element is present in the array or not. |
10 | indexof() | indexof() Method is used to find the index of the element provided as the argument to the function. |
11 | join() | join() method is used to join all elements of an Array into a string. |
12 | Keys() | Keys() method is used to return an Array Iterator object with the keys of an array. |
13 | lastIndexof() | lastIndexof() method returns the last position of a value, or it return -1 if the value is not found. |
14 | map() | map() method forms a new array with the result of calling a function for every element. |
15 | reduce() | reduce() method reduces the elements of an array into a single value. |
16 | reduceRight() | reduceRight() method reduces the elements of an array into a single value. |
17 | reverse() | reverse() method is used to reverse the array. |
18 | set() | set() method is used to store values into the given array. |
19 | Slice() | slice() method gives the selected elements of the array on which is implemented. |
20 | some() | some() method examines the elements of the array that satisfies the given condition or not. |
21 | sort() | sort() method is used to sort the array and return the updated array. |
22 | subarray() | subarray() method returns a new array and it does not change the original array. |
23 | values() | values() method is used to define the value of the contents in the array |
24 | toLocaleString() | toLocaleString() method is used to convert the element of the given array into a string. |
25 | toString() | toString() method is used to convert the element of the given array into a string. And these Strings are separated by such as a comma “,”. |