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


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

Syntax

util.types.isInt16Array(value)

Parameters

It takes only one parameter −

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

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

Example 1

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

// util.types.isInt16Array() Demo Example

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

// Passing normal Int16-Array as input value
console.log("1. " + util.types.isInt16Array(new Int16Array()));

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

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

Output

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

Example 2

// util.types.isInt16Array() Demo Example

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

// Defining a int16 array
var int16 = new Int16Array();
int16[0] = 42;

// Defining another int16 array
var arr = new Int16Array([21,31]);

// Passing int16 Array with values as input
console.log("1. " + util.types.isInt16Array(arr));

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

Output

C:\home
ode>> node isInt16Array.js 1. true 2. true

Updated on: 18-Aug-2021

52 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements