Open In App

JavaScript RegExp hasIndices Property

Last Updated : 01 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

JavaScript RegExp hasIndices property is used to check whether the ‘d’ flag is used in Regular Expressions or not. If the ‘d’ flag is set then this property returns true else false. 

Syntax:

Regexpobj.hasIndices

Return Value: A boolean value.

Example 1: This example prints on the console whether the ‘d’ modifier is present or not.

Javascript




function hasIndices_prop() {
    let regex = new RegExp(/[a-d]/, 'd');
    console.log(regex.hasIndices)
}
 
hasIndices_prop();


Output

true

Example 2: This example checks whether the ‘d’ flag is used or not.

Javascript




function hasIndices_prop() {
    let regex = new RegExp(/[a-d]/, 'd');
 
    if (regex.hasIndices) {
        console.log("d Modifier is present");
    } else {
        console.log("d Modifier is absent");
    }
}
 
hasIndices_prop();


Output

d Modifier is present

Supported Browsers:

  • Chrome 90
  • Edge 90
  • Firefox 88
  • Opera 76
  • Safari 15

We have a complete list of Javascript RegExp expressions, to check those please go through this JavaScript RegExp Reference article.


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

Similar Reads