MZ How to run a for loop that checks actor names against character names and saves as a variable?

Every single thing I've tried so far has turned up an error, or said functions that I used in other scripts weren't, in fact, functions. I just want to run a for loop for every actor, then check the actor name against the current event name (stored in the variable at #10).

Code:
for (let i = 1; i < $gameActors._data.length; i++) {
    if ($gameActors._data[i] && $gameActors._data[i].name() == $gameVariables.value(10)){
        $gameVariables.setValue(11, actor.actorId())};
Don't use $gameActors._data[i]. It is "lazily filled", which means that there could be actors that are defined in your database but just completely missing in the list. Instead, use $gameActors.actor(i). It should be safe to use $gameActors._data.length, as long as you only care about actors that are actually in the party.

Though that's not your problem, it does let you shorten the code by omitting the $gameActors._data[i] && prefix.

I think that seems like the most likely cause of your issue – one of the actors hasn't been initialized yet, so $gameActors._data[i].name() won't work. I don't see any other obvious issues, but if you do have further issues after making that correction, post the exact error message.
you have a missing closing parenthesis for the loop and actor on that last line wouldnt be defined
Code:
for (let i = 1; i < $gameActors._data.length; i++) {
    if ($gameActors._data[i] && $gameActors._data[i].name() == $gameVariables.value(10)){
        $gameVariables.setValue(11, $gameActors._data[i].actorId());
    };
};
Assuming that you want to keep overwriting variable 11 every time it finds an actor with a name that matches variable 10, you could use a for-of loop to iterate through the array (edit my mistake - array might have a null so use this edit):
JavaScript:
for (const actor of $gameActors._data) {
  if (actor && actor.name() === $gameVariales.value(10)) {
    $gameVariables.setValue(11, actor.actorId());
  }
}

If you want the loop to stop after finding a match, you can use .find() (you could add a break in the condition of the loop as well for pretty much the same thing):
JavaScript:
const actor = $gameActors._data.find(a => a && a.name() === $gameVariables.value(10));
if (actor) $gameVariables.setValue(11, actor.actorId());
you have a missing closing parenthesis for the loop and actor on that last line wouldnt be defined
Code:
for (let i = 1; i < $gameActors._data.length; i++) {
    if ($gameActors._data[i] && $gameActors._data[i].name() == $gameVariables.value(10)){
        $gameVariables.setValue(11, $gameActors._data[i].actorId());
    };
};
yeah i caught this after a good sleep and a few more hours of staring at it lol.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-run-a-for-loop-that-checks-actor-names-against-character-names-and-saves-as-a-variable.180663/