Open In App

JavaScript RegExp hasIndices Property

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.






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.




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:

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

Article Tags :