Node.js util.types.isUint8Array() Method
Last Updated :
04 Apr, 2023
The util.types.isUint8Array() method of the util module which is primarily designed to support the needs of Node.js own Internal APIs. It is used to check whether the passed instance in the method is a built-in Uint8Array instance or not.
Syntax:
util.types.isUint8Array( value )
Parameters: This method accepts a single parameter
value that holds any value, i.e instance of any module.
Return value: This method returns a Boolean value, i.e true if the passed value is an instance of Uint8Array otherwise returns
false.
The below examples illustrate the use of util.types.isUint8Array() method in Node.js:
Example 1:
javascript
const util = require( 'util' );
console.log(util.types.isUint8Array( new Set()));
console.log(util.types.isUint8Array( new Uint8Array()));
|
Output:
false
true
Example 2:
JavaScript
const util = require( 'util' );
const array1 = new Uint8Array(2);
array1[0] = 42;
console.log(util.types.isUint8Array(array1));
const array2 = new Uint8Array([21, 31]);
console.log(util.types.isUint8Array(array2));
const array3 = new Uint8Array([21, 31]);
const array4 = new Uint8Array(array3);
console.log(util.types.isUint8Array(array4));
const array5 = new Int16Array(2);
array5[0] = 10;
console.log(util.types.isUint8Array(array5));
|
Output:
true
true
true
false
Reference: https://nodejs.org/api/util.html#util_util_types_isuint8array_value
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...