Node.js util.types.isUint16Array() Method
Last Updated :
11 Apr, 2023
The util.types.isUint16Array() (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 Uint16Array or not in the node.js. If the value passed is of type ‘Uint16Array’ then it returns ‘true’ otherwise returns ‘false’.
Syntax:
const util = require('util');
util.types.isUint16Array( 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, JavaScript primitive, or any datatype.
Return Value<Boolean>: This returns a boolean value. If the value passed is of type ‘Uint16Array’ then it returns ‘true’ otherwise returns ‘false’.
Example 1: The below example illustrates the use of util.types.isUint16Array() method in Node.js.
Filename: index.js
javascript
const util = require( 'util' );
const { types } = require( 'util' );
console.log( "1.>" , util.types.isUint16Array(
new ArrayBuffer()));
console.log( "2.>" , util.types.isUint16Array(
new Uint16Array(60)));
console.log( "3.>" , util.types.isUint16Array(
new Uint16Array(500)));
console.log( "4.>" , types.isUint16Array(
new Uint32Array()));
console.log( "5.>" , types.isUint16Array(
new Uint16Array([1, 5, 8, 1, 95])));
console.log( "6.>" , util.types.isUint16Array(
new Float64Array(64)));
console.log( "7.>" , util.types.isUint16Array(
new Int8Array(8)));
|
Run the index.js file using the following command:
node index.js
Output:
1.> false
2.> true
3.> true
4.> false
5.> true
6.> false
7.> false
Example 2: The below example illustrates the use of util.types.isUint16Array() method in Node.js.
Filename: index.js
javascript
const util = require( 'util' );
const { types } = require( 'util' );
console.log( "1.>" , util.types.isUint16Array(
new BigInt64Array()));
console.log( "2.>" , util.types.isUint16Array(
new BigUint64Array()));
console.log( "3.>" , util.types.isUint16Array(
new Float32Array()));
console.log( "4.>" , util.types.isUint16Array(
new Int8Array()));
console.log( "5.>" , util.types.isUint16Array(
new Int16Array()));
console.log( "7.>" , types.isUint16Array(
new Uint8Array()));
console.log( "8.>" , types.isUint16Array(
new Float64Array()));
let var1 = new Uint16Array();
let var2 = new Int16Array();
if (util.types.isUint16Array(var1))
console.log( "Yes, the value is a isUint16Array." );
else
console.log( "No, provided value is not a isUint16Array" );
if (util.types.isUint16Array(var2))
console.log( "Yes, the value is a isUint16Array." );
else
console.log( "No, provided value is not a isUint16Array" );
|
Run index.js file using the following command:
node index.js
Output:
1.> false
2.> false
3.> false
4.> false
5.> false
6.> false
7.> false
8.> false
Yes, the value is a isUint16Array.
No, provided value is not a isUint16Array
Reference: https://nodejs.org/api/util.html#util_util_types_isuint16array_value
Share your thoughts in the comments
Please Login to comment...