Node.js – util.types.isInt8Array() Method


The util.types.isInt8Array() method checks whether the passed value is a built-in Int8Array instance or not. If the above condition is satisfied, it returns True, else False.

Syntax

util.types.isInt8Array(value)

Parameters

It takes a single parameter −

  • value − This input value takes input for the required parameter and checks if it's an Int8Array instance or not.

It returns True or False based upon the input value passed.

Example 1

Create a file with the name "isInt8Array.js" and copy the following code snippet. After creating the file, use the command "node isInt8Array.js" to run this code.

// util.types.isInt8Array() Demo Example

// Importing the util module
const util = require('util');

// Passing normal Int32-Array as input value
console.log("1." + util.types.isInt8Array(new Int8Array()));

// Passing a Array buffer as input
console.log("2." + util.types.isInt8Array(new ArrayBuffer()));

// Passing a Float64 array as input
console.log("3." + util.types.isInt8Array(new Int16Array()));

Output

C:\home
ode>> node isInt8Array.js 1.true 2.false 3.false

Example 2

Let’s have a look at one more example

// util.types.isInt8Array() Demo Example

// Importing the util module
const util = require('util');

var int8 = new Int8Array(2);
int8[0] = 21;

// From an array
var arr = new Int8Array([21,31]);
console.log(arr[0]);

// From an ArrayBuffer
var buffer = new ArrayBuffer(8);
var z = new Int8Array(buffer, 1, 4);

// From an iterable
var iterable = function*(){ yield* [1,2,3]; }();
var arr1 = new Int8Array(iterable);

// Passing int8 Array with values as input
console.log("1." + util.types.isInt8Array(int8));

// Passing a int8 array 0th value as input
console.log("2." + util.types.isInt8Array(arr));

// Passing a int8 array defined by array buffer
console.log("3." + util.types.isInt8Array(z));

// Passing a int8 array defined by iterable
console.log("4." + util.types.isInt8Array(arr1));

Output

C:\home
ode>> node isInt8Array.js 21 1.true 2.true 3.true 4.true

Updated on: 18-Aug-2021

40 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements