Saturday, October 18, 2025
HomeLanguagesJavascriptJavaScript Uint8Array.of() Method

JavaScript Uint8Array.of() Method

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.

Syntax:

Uint8Array.of(el0, el1, el2, .., eln)

Parameters:

  • 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.

JavaScript




<script>
    // Creating a Uint8Array from a array by 
    // Creating the array from the Uint8Array.of() method
    let uint8Arr = new Uint8Array;
    uint8Arr = Uint8Array.of('41', '51', '56', '8', '24');
       
    // Printing the result
    console.log(uint8Arr);
</script>


Output:

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.

JavaScript




<script>
    // Create a Uint8Array from a array by 
    // Creating the array from the Uint8Array.of() method
    let uint8Arr = new Uint8Array;
     
    // Accepts the uint8 values
    uint8Arr = Uint8Array.of(-49999, 5, 7, 799, 8);
     
    // Print the result
    console.log(uint8Arr);
</script>


Output:

Uint8Array(5) [177, 5, 7, 31, 8]

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS