For loops issue


when I push j to the array, the console is printing out commas, can't figure out why!

var text = " Drew, fkfdskjh Drew fmksfda. Drew asdsadf";
var myName = "Drew";
var hits = [];

for (var i = 0; i < text.length; i++) {
    if (text[i] === "D") {
        for (var j = i; j < myName.length + i; j++);



Check your second for loop.

syntax of for loop

for (first par; second part;third part) {
  //your code

Your for loops have semicolons like this (below) which is not acceptable in javascript..

for (first part; second part;third part) ; {
//your code

Also you missed the {}, even by default it should work for just one line of code but its safe to use brackets there.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.