Sunday, November 17, 2024
Google search engine
HomeLanguagesJavascriptUnderscore.js _.isMap() Function

Underscore.js _.isMap() Function

Underscore.js is a library in javascript that makes operations on arrays, string, objects much easier and handy. _.isMap() function is used to check whether the given object is javascript Map or not.

Note: It is very necessary to link the underscore CDN before going and using underscore functions in the browser. When linking the underscore.js CDN The “_” is attached to the browser as a global variable.

Syntax:

_.isMap(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 Map of javascript it returns true otherwise false is returned by the function.

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

Example 1:

When an array is given the output is false.




<!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 _.isMap()
    var isMap= _.isMap(obj);
    console.log(isMap)
    //If the given object is Map it prints the object is Map.
    if(isMap)
    console.log(`The ${obj} is the Map of Javascript.`)
    else
    console.log(`The ${obj} is not the Map of Javascript.`)
  </script>
</body>
</html>


Output:

Example 2:

When a Map is given it returns true.




<!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 Map using constructor
    var obj= new Map();
    //using the underscore.js function _.isMap()
    var isMap= _.isMap(obj);
    console.log(isMap)
    //If the given object is Map it prints the object is Map.
    if(isMap)
    console.log(`The ${obj} is the Map of Javascript.`)
    else
    console.log(`The ${obj} is not the Map of Javascript.`)
  </script>
</body>
</html>


Output:

Example 3:

When giving an object as a parameter the output is false




<!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 Javascript Object using constructor
    var obj= new Object();
    obj={
      "a":1,
      "b":2
    }
    //using the underscore.js function _.isMap()
    var isMap= _.isMap(obj);
    console.log(isMap)
    //If the given object is Map it prints the object is Map.
    if(isMap)
    console.log(`The ${obj} is the Map of Javascript.`)
    else
    console.log(`The ${obj} is not the Map of Javascript.`)
  </script>
</body>
</html>


Output:

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments