Latest

recent

JavaScript lastIndex Property

Definition and Usage

The lastIndex property specifies the index (placement) in the string where to start the next match.
The index is a number specifying the placement of the first character after the last match.
This property only works if the "g" modifier is set.

Syntax

RegExpObject.lastIndex


Example

In the following example we will see the index of the string after a match is found:

<script type="text/javascript">
var str = "The rain in Spain stays mainly in the plain";
var patt1 = new RegExp("ain", "g");
patt1.test(str);
document.write("Match found. index now at: " + patt1.lastIndex);
</script>
JavaScript lastIndex Property Reviewed by 1000sourcecodes on 22:17 Rating: 5
Powered by Blogger.