How to use JavaScript lastIndex Property

This article describe about JavaScript lastIndex Property.
  • 2015

JavaScript lastIndex Property

This property define the index at which to start the next match.
 Note: If "g" modifier set then work this property.
 For define character position this property return the an integer immediately after the last match found by exec( ) or test( ) methods.
 Note: set lastIndex to 0 by exec() and test() if they do not get a match.




<!DOCTYPE html>



<script type="text/javascript">

    var str = "The boy climbed on The wall.";

    var pattern = /The/g;


    while (pattern.test(str) == true) {

        document.write("'The' found. Index now at: " + pattern.lastIndex);

        document.write("<br />");








You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.