Node.js | util.types.isSet() Method

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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())); 

chevron_right


Output:

true
false

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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())); 

chevron_right


Output:

true
true
false

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.