Loading lesson path
Concept visual
Start from A
Binary Data. Unlike arrays, typed arrays are buffers of Fixed Length.
Formula
Fixed Types like 8 - bit integers or 32 - bit numbers.Create a typed array of 5 bytes:
const myArr = new Uint8Array(5);Create a typed array from an array:
const myArr = new Uint8Array([0,1,2,3,4]);Create a typed array from a list of numbers:
const myArr = Uint8Array.of(0,1,2,3,4);Create a typed array from an array:
const myArr = Uint8Array.from([0,1,2,3,4]);Typed Arrays were designed to provide an efficient way to handle binary data, unlike traditional JavaScript arrays which can hold elements of mixed data types. Typed arrays are raw memory, so JavaScript can pass them directly to any function without converting the data to another representation. Typed arrays are seriously faster than normal arrays for passing data to functions that can use raw binary data. Typed Arrays are highly suitable for:
Fast graphics rendering and image processing.
Fast reading and writing of local files.
Fast handling of audio and video data.
Efficient binary data transfer over network. Typed arrays provide a way to handle binary data as efficiently as arrays work in C.
Fetch API Example fetch(url).then(request => request.arrayBuffer()).then(arrayBuffer =>...);const canvas = document.getElementById('my_canvas');
const context = canvas.getContext('2d');
const imageData = context.getImageData(0, 0, canvas.width, canvas.height);
const uint8ClampedArray = imageData.data;Typed Arrays cannot be dynamically resized using methods like push() or pop().
Elements must adhere to the specified data type of the typed array.
Typed Arrays are views into an ArrayBuffer, allowing direct manipulation of binary data.
-128 127
byte
255
octet
255
octet