Open In App

Underscore.js _.isSet() Function

Last Updated : 01 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isSet() function is used to check whether the given object is javascript set or not. When linking the underscore.js CDN The “_” is attached to the browser as global variable.

Syntax:

_.isSet(object);

Parameters: 

  • object: It is any JavaScript object such as array, string, maps, set etc.

Returns: It returns the boolean value. If the object is a JavaScript set, it returns true otherwise false is returned by the function.

Few Examples are given below for a better understanding of the function.

Note: It is necessary to link the CDN of UnderScore.js before running code in the browser.

Example 1: When an Set is given the output is True.

html




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charMap="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src=
  </script
</head>
<body>
  <script>
    //creating a set using constructor
    var obj= new Set();
    //using the underscore.js function _.isSet()
    var isSet= _.isSet(obj);
    console.log(isSet)
    //If the given object is Set it prints the object is set
    if(isSet)
    console.log(`The ${obj} is the Set of Javascript.`)
    else
    console.log(`The ${obj} is not the Set of Javascript.`)
  </script>
</body>
</html>


Output:

Example 2: When a Array is given it returns False.

html




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charMap="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src=
  </script
</head>
<body>
  <script>
    //creating a array of size 2 using constructor
    var obj= new Array(2);
    //filling array with value 10
    obj.fill(10);
    //using the underscore.js function _.isSet()
    var isSet= _.isSet(obj);
    console.log(isSet)
    //If the given object is Set it prints the object is Set.
    if(isSet)
    console.log(`The ${obj} is the Set of Javascript.`)
    else
    console.log(`The ${obj} is not the Set of Javascript.`)
  </script>
</body>
</html>


Output:



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads