Lodash _.isRegExp() Method
Lodash _.isRegExp() method is used to find whether the given value is a regular expression or not. It returns True if the given value is a regular expression. Otherwise, it returns false.
Syntax:
_.isRegExp(value);
Parameters:
- value: This parameter holds the value to check.
Return Value:
This method returns true if the value is a regular expression, else false.
Example 1: In this example, we are passing a regular expression to the lodash _.isRegExp() method. the object starts and ends with ‘/’, therefore it is a regular expression. Hence, the result is true.
javascript
const _ = require( "lodash" );
console.log(_.isRegExp(/gfg/));
|
Output:
true
Example 2: In this example, we are passing a string to the _.isRegExp() function Since a string is not a regular expression, the output will be false.
javascript
const _ = require( "lodash" );
console.log(_.isRegExp( 'gfg' ));
|
Output:
false
Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.
Reference: https://lodash.com/docs/4.17.15#isRegExp
Last Updated :
27 Oct, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...