Quote:
Originally Posted by kpaccess
In Chapter-5
StringTypeLocationMethodsExample02.htm
var stringValue = "Lorem inpus dolor sit amet, consectetur adipisicing elit";
var positions = new Array();
var pos = stringValue.indexOf("e");
while(pos > -1){
position.push(pos);
Here can't we just say
instead of
pos = stringValue.indexOf("e", pos + 1);
can't we simple use
pos ++;
}
|
The pos variable is not simple moving an index forward, it is specifically moving forward to each match. The line before the one that you want to change takes the value of pos and saves it to an array, because it is the location of one of the matches.