Open In App

Lodash _.exists() Method

Last Updated : 30 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The Lodash _.exists() method checks whether the given value is Exist or not and returns the corresponding boolean value. Both null and undefined are considered non-existy values. All other values are “Existy”.

Syntax:

_.exists( value );

Parameters: This method accepts single parameter as mentioned above and described below:

  • value: Given value to be checked for Existy value.

Return Value: This method returns a Boolean value true if the given value is Existy, else false.

Note: This will not work in normal JavaScript because it requires the lidash.js contrib library to be installed. Lodash.js contrib library can be installed using npm install lodash-contrib.

Example 1:

Javascript




// Defining underscore lodash variable 
var _ = require('lodash-contrib'); 
  
var bool = _.exists("Geeks");
    
console.log("Check the Existenc of Given Value : ", bool);


Output:

Check the Existenc of Given Value : true

Example 2:

Javascript




// Defining underscore lodash variable 
var _ = require('lodash-contrib'); 
  
var bool = _.exists(undefined); 
    
console.log("Check the Existenc of Given Value : ", bool);


Output:

Check the Existenc of Given Value : false

Example 3:

Javascript




// Defining underscore lodash variable 
var _ = require('lodash-contrib'); 
  
var bool = _.exists(null);
    
console.log("Check the Existenc of Given Value : ", bool);


Output:

Check the Existenc of Given Value : false

Example 4:

Javascript




// Defining underscore lodash variable 
var _ = require('lodash-contrib'); 
  
var bool = _.exists([1, 12, 2, 3]);
    
console.log("Check the Existenc of Given Value : ", bool);


Output:

Check the Existenc of Given Value : true


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

Similar Reads