Saturday, September 6, 2025
HomeLanguagesJavascriptJavaScript TypedArray.of() Method

JavaScript TypedArray.of() Method

The TypedArray.of() method is used to create a new array from a variable number of arguments that are passed to it.

Syntax:

TypedArray.of( el0, el1, el2, ...elN )

Parameters: This method accepts a variable number of elements, which are used to create the Int16Array array.

TypedArray can contain any of the below-mentioned values:

Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array

Return Value: This method returns a new TypedArray instance.

The below example illustrates the TypedArray.of() Method in JavaScript:

Example 1: In this example, the values passed are the character values that are converted to Int16 by the method.

JavaScript




<script>
    // Create a Uint16Array by using
    // the Int16Array.of() method
    let int16Arr = new Int16Array;
    int16Arr =
      Int16Array.of('31', '52', '16', '80', '24');
      
    // Print the result 
    console.log(int16Arr);
</script>


Output:

[31, 52, 16, 80, 24]

Example 2: In this example, the values passed are the Integer values which are converted to Int16 by the method. The value -499999 is converted to 15537.

JavaScript




<script>
    // Create a Uint16Array by using
    // the Int16Array.of() method
    let int16Arr = new Int16Array;
      
    // Accepts the Int16 values
    int16Arr =
      Int16Array.of(-49999, 5, 7, 799, 8); 
      
    // Print the result 
    console.log(int16Arr); 
</script>


Output:

[15537, 5, 7, 799, 8]

Example 3: In this example, the values passed are the character values that are converted to Uint16 by the method.

JavaScript




<script>
    // Create a Uint16Array by using
    // the Uint16Array.of() method
    let uint16Arr = new Uint16Array;
    uint16Arr =
      Uint16Array.of('31', '50', '26', '60', '24');
      
    // Print the result 
    console.log(uint16Arr); 
</script>


Output:

[31, 50, 26, 60, 24]

Example 4:In this example, the values passed are the Integer values which are converted to Uint16 by the method. The value -499999 is thus converted to 24289.

JavaScript




<script>
    // Create a Uint16Array by using
    // the Uint16Array.of() method
    let uint16Arr = new Uint16Array;
      
    // Accepts only the Uint16 values
    uint16Arr = 
      Uint16Array.of(-499999, 5, 7, 799, 8);
      
    // Print the result 
    console.log(uint16Arr);
</script>


Output:

[24289, 5, 7, 799, 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!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS