Open In App

Node.js util.types.isUint32Array() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The util.types.isUint32Array() (Added in v10.0.0) method is an inbuilt application programming interface of the util module which is used to check whether the value passed is of type Uint32Array (i.e, Unsigned 32 bit Array) or not in the node.js.  ranges from 0 to 4294967295 with 4-byte memory size. If the value passed is of type ‘Uint32Array’ then it returns ‘true’ otherwise returns ‘false’.

Syntax:

const util = require('util');
util.types.isUint32Array( value )

Parameters: This method accepts a single parameter as mentioned above and described below.

  • value <any>: It is a required parameter that accepts any variable, Class, Function, Object, or JavaScript primitive or any datatype.

Return Value:<Boolean>: This returns a boolean value. If the value passed is of type ‘isUint32Array’ then it returns ‘true’ otherwise returns ‘false’.

Below examples illustrate the use of util.types.isUint32Array() method in Node.js.

Example 1: Filename: index.js




// Node.js program to demonstrate the
// util.types.isUint32Array() method
  
// Using require to access util module
const util = require('util');
const { types } = require('util');
  
// Passing ArrayBuffer as parameter
console.log("1.>", util.types.isUint32Array(
        new ArrayBuffer()));
// Returns false
  
// Passing Uint16Array with argument as parameter
console.log("2.>", util.types.isUint32Array(
        new Uint16Array(64)));
// Returns true
  
// Passing UintArray with JSON data as parameter
console.log("3.>", util.types.isUint32Array(
    new Uint32Array([{
    1: '1',
    5: "hii", f: '8', a: 1, af: 4294967295
}])));
// Returns true
  
// Passing Uint32Array as parameter
console.log("4.>", util.types.isUint32Array(
        new Uint32Array()));
// Returns true
  
// Passing data as parameter from 0 to 4294967295
console.log("5.>", util.types.isUint32Array(
    new Uint32Array([1, 5, 8, 1, 4294967295])));
// Returns true
  
// Passing Float64Array as parameter
console.log("6.>", util.types.isUint32Array(
            new Float64Array(64)));
// Returns false
  
// Passing Int8Array as parameter
console.log("7.>", util.types.isUint32Array(
            new Int8Array(8)));
// Returns false


Run index.js file using the following command:

node index.js

Output:

1.> false

2.> false

3.> true

4.> true

5.> true

6.> false

7.> false

Example 2: Filename: index.js




// Node.js program to demonstrate the
// util.types.isUint32Array() method
  
// Using require to access util module
const util = require('util');
const { types } = require('util');
  
// Passing BigInt64Array as parameter
console.log("1.>", util.types.isUint32Array(
            new BigInt64Array()));
// Returns false
  
// Passing BigUint64Array as parameter
console.log("2.>", util.types.isUint32Array(
            new BigUint64Array()));
// Returns false
  
// Passing Float32Array as parameter
console.log("3.>", util.types.isUint32Array(
            new Uint32Array()));
// Returns false
  
// Passing Int8Array as parameter
console.log("4.>", util.types.isUint32Array(
            new Int8Array()));
// Returns false
  
// Passing Int16Array as parameter
console.log("5.>", util.types.isUint32Array(
            new Int16Array()));
// Returns false
  
// Passing Uint8Array as parameter
console.log("6.>", types.isUint32Array(
            new Uint8Array()));
// Returns false
  
// Passing Float64Array as parameter
console.log("7.>", types.isUint32Array(
            new Float64Array()));
// Returns false
  
var var1 = new Uint32Array();
var var2 = new Int16Array();
  
// Calling util.types.isUint32Array() method
if (util.types.isUint32Array(var1))
    console.log("Yes, the value is a isUint32Array.");
else
    console.log("No, provided value is not a isUint32Array");
  
// Calling util.types.isUint32Array() method
if (util.types.isUint32Array(var2))
    console.log("Yes, the value is a isUint32Array.");
else
    console.log("No, provided value is not a isUint32Array");


Run index.js file using the following command:

node index.js

Output:

1.> false

2.> false

3.> true

4.> false

5.> false

6.> false

7.> false

Yes, the value is a isUint32Array.

No, provided value is not a isUint32Array

Reference: https://nodejs.org/api/util.html#util_util_types_isuint32array_value



Last Updated : 13 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads