The Uint8Array array represents an array of 8-bit unsigned integers. The values are initialized by 0. Elements in the array can be referenced by the object’s methods or using a standard syntax (by bracket notation).
The Uint8Array.of() method creates a new typed array from a variable number of arguments.
Uint8Array.of(el0, el1, el2, .., eln)
- n-elements: This method accepts the number of elements, which are basically the element for which the array is to be created.
Return Value: This method returns a new Uint8Array instance.
Example 1: In this example, the values passed are the character values that are converted to Uint8 by the method.
Uint8Array(5) [41, 51, 56, 8, 24]
Example 2: In this example, the values passed are the int values that are converted to Uint8 by the method. -49999 and 799 converted to 177 and 31 respectively.
Uint8Array(5) [177, 5, 7, 31, 8]