"Fix your code" warning, but everything works as it should

In a Dungeon Arena I decided to help myself with writing some help-functions.
Wrote a small function that helps me to find enemy hero. And it worked just fine before reloading the page.
I hope, I am allowed to post code here, so here it is:

function findKnight(enemies) {   
    if (enemies.length === 0) return false;
    for (var i=0; i<enemies.length, enemies[i].type!='knight' ; i++) {}
    return enemies[i];
}

After page reload a warning “Fix your code” appeared, lighting up the “enemies[i].type” string.
It is clear, that this variable may not have such a property, but in that case, what should I do? Create a prototype? )
But “submit” button still works fine :smile:

When changed loop to

for (var i=0; i<enemies.length; i++) {
    if (enemies[i].type=='knight') break;
}

warning disappeared. Don’t like “breaks”…

So the part that didn’t work is using the comma operator in the for-loop condition?

It DOES work! And that is kinda funny.
Coma simply separates the listed “until” statements in “for” loop.
Again: the problem was in highlighting a working code.

Plz, just kill this topic…