Here is an animation of the string search loop from the JavaScript code. It will display the values of the variables and expressions used in the code and highlight where it is at each step.
Search String | Target Character | Number Found | loop index i | str.length | str.charAt(i) | Program Counter |
---|---|---|---|---|---|---|
for(i = 0; i < str.length; i++) { if(str.charAt(i) == target) { charcount++; } } // for |