Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Int8Array of() Method

JavaScript Int8Array of() Method

The Int8Array constructor represents an array of two’s-complement of 8-bit signed integers. By default, the contents of Int8Array are initialized to 0. The Int8Array.of() method is used to create a new Int8Array from an array-like or iterable object.

Syntax:

Int8Array.of(el0, el1, ...)

Parameter: This method accepts the number of elements, which are basically the elements for which the array is created.

Return Value: This method returns a new Int8Array instance.

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

HTML




<script>
    // Create a Int8Array from a array
    // by creating the array from the
    // Int8Array.of() method
    let int8Arr = new Int8Array;
    int8Arr = Int8Array.of('1', '5', '2', '8', '14');
       
    // Print the result
    console.log(int8Arr);
</script>


Output:

[1, 5, 2, 8, 14]

Example 2: In this example, the values passed are the integer values which are converted to Int8 by the method. 49999 and 799 are converted to 79 and 31 respectively.

Javascript




<script>
    // Create a Int8Array from a array
    // by creating the array from the
    // Int8Array.of() method
    let int8Arr = new Int8Array;
     
    // Accepts the int8 values
    int8Arr = Int8Array.of(49999, 5, 6, 799, 8);
       
    // Print the result
    console.log(int8Arr);
</script>


Output:

[79, 5, 6, 31, 8]
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

Recent Comments