The util.types.isSet() method of util module 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 Set instance or not.
Syntax:
util.types.isSet( 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 a built-in instance of Set otherwise returns false.
Below examples illustrate the use of util.types.isSet() method in Node.js:
Example 1:
// Node.js program to demonstrate the // util.types.isSet() method // It includes util module const util = require( 'util' ); // Return true as passed instance is of Set console.log(util.types.isSet( new Set())); // Return false as passed instance is of Map console.log(util.types.isSet( new Map())); |
Output:
true false
Example 2:
// Node.js program to demonstrate the // util.types.isSet() method // It includes util module const util = require( 'util' ); // Making a set object of a string var set1 = new Set( "geeksforgeeks" ); // Return true as passed instance is of Set console.log(util.types.isSet(set1)); const numbers = [2, 3, 4, 4, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 5, 32, 3, 4, 5]; // Making a set object of array var set2 = new Set(numbers); // Return true as passed instance is of Set console.log(util.types.isSet(set2)); // Return false as passed instance is of Map console.log(util.types.isSet( new Map())); |
Output:
true true false
Reference: https://nodejs.org/api/util.html#util_util_types_isset_value
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.