VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-isregexp-method/

⇱ Lodash _.isRegExp() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.isRegExp() Method

Last Updated : 4 Sep, 2024

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. 

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.  

Output:

false

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.

Comment