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


The util.types.isAnyArrayBuffer() checks whether the passed value is an ArrayBuffer or a SharedArrayBuffer instance. It returns True if the above condition holds, else False.

Syntax

util.types.isAnyArrayBuffer(value)

Parameters

It takes a single parameter −

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

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

Example 1

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

// util.types.isAnyArrayBuffer() Demo Example

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

// Printing the response received...
console.log("1. " + util.types.isAnyArrayBuffer(new ArrayBuffer()));
console.log("2. " + util.types.isAnyArrayBuffer(21));
console.log("3. " + util.types.isAnyArrayBuffer("TutorialsPoint"));

Output

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

Example 2

Let’s have a look at one more example

// util.types.isAnyArrayBuffer() Demo Example

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

// Checking if its a SharedArrayBuffer
console.log("1. " + util.types.isAnyArrayBuffer(new
SharedArrayBuffer()));

// Checking if Date is of array buffer instance
console.log("2. " + util.types.isAnyArrayBuffer(new Date));

// Creating a 16 byte array buffer
var buffer = new ArrayBuffer(16);
console.log("3. " + util.types.isAnyArrayBuffer(buffer));

//Create a Int8Array view referring to the buffer
var buf = new Int8Array(buffer);
console.log("4. " + util.types.isAnyArrayBuffer(buf));

Output

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

Updated on: 18-Aug-2021

44 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements