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


The util.types.isFloat32Array() method checks whether the passed value is a builtin Float32Array instance or not. If the above condition is satisfied, it returns True, else False.

Syntax

util.types.isFloat32Array(value)

Parameters

It takes a single parameter −

  • value − This input value takes input for the required parameter and checks if it's a Float32-Array instance or not.

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

Example 1

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

// util.types.isFloat32Array() Demo Example

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

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

// Passing a Float32 array instance as input
console.log("2." + util.types.isFloat32Array(new Float32Array()));

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

Output

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

Example 2

Let’s have a look at one more example

// util.types.isFloat32Array() Demo Example

// Importing the util module
const util = require('util');
var float32 = new Float32Array(2);
float32[0] = 21;

// From an array
var arr = new Float32Array([21,31]);

// From an ArrayBuffer
var buffer = new ArrayBuffer(16);
var z = new Float32Array(buffer, 0, 4);

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

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

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

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

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

Output

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

Updated on: 18-Aug-2021

29 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements