Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Node.js util.types.isUint8Array() Method

  • Last Updated : 13 Oct, 2021

The util.types.isUint8Array() method of 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 which 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 instance of Uint8Array otherwise returns false.

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

Example 1:




// Node.js program to demonstrate the    
// util.types.isUint8Array() method 
    
// It includes util module 
const util = require('util'); 
    
// Return false as passed instance is of set 
console.log(util.types.isUint8Array(new Set())); 
    
// Return true as passed instance is of Uint8Array 
console.log(util.types.isUint8Array(new Uint8Array())); 

Output:

false
true

Example 2:




// Node.js program to demonstrate the    
// util.types.isUint8Array() method 
    
// It includes util module 
const util = require('util'); 
    
// Making an instance of Uint8Array 
// of size 2 
var array1 = new Uint8Array(2); 
    
// Initializing the zeroth element  
array1[0] = 42; 
    
// Returns true as passed instance
// is of Uint8Array 
console.log(util.types.isUint8Array(array1)); 
     
// Making an instance of Uint8Array 
var array2 = new Uint8Array([21, 31]); 
    
// Returns true as passed instance
// is of Uint8Array 
console.log(util.types.isUint8Array(array2)); 
    
// Making an instance of Uint8Array 
var array3 = new Uint8Array([21, 31]); 
    
// Making another instance of Uint8Array by 
// passing an instance of Uint8Array 
var array4 = new Uint8Array(array3); 
    
// Returns true as passed instance
// is of Uint8Array 
console.log(util.types.isUint8Array(array4)); 
    
// Making an instance of Int16Array of size 2 
var array5 = new Int16Array(2); 
    
// Initializing the zeroth element  
array5[0] = 10; 
    
// Returns false as passed instance
// is of Int16Array 
console.log(util.types.isUint8Array(array5)); 

Output:

true
true
true
false

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!