Lodash _.isRegExp() Method
The _.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.
Parameters: This method accepts a single parameter as mentioned above and described below:
value: This parameter holds the value to check.
Return Value: This method returns true if the value is a regular expression, else false.
Note: Here, const _ = require(‘lodash’) is used to import the lodash library into the file.
Example 1: Passing a regular expression to the _.isRegExp() function
Here, the object starts and ends with ‘/’, therefore it is a regular expression. Hence, the result is true.
Example 2: Passing a string to the _.isRegExp() function
Since a string is not a regular expression therefore, the output will be false.
Example 3: Passing a string with ‘/’ to _.isRegExp() function
Hence the overall object is a string., the output will be false.