How can I add and remove state to all enemies with a javascript command?

I know this may be a silly question... But, is there a command like user.addState(x); but capable of affecting all enemies in battle??
This should do it - $gameTroop refers to the current troop and the aliveMembers method on it returns all the enemies in the troop that don't have the death state applied.

JavaScript:
// Replace x with the state Id you want to add
$gameTroop.aliveMembers().forEach(enemy => enemy.addState(x));

If you're using an older version of MV that doesn't support ES6:
JavaScript:
$gameTroop.aliveMembers().forEach(function(member) {
    member.addState(x);
});
This should do it - $gameTroop refers to the current troop and the aliveMembers method on it returns all the enemies in the troop that don't have the death state applied.

JavaScript:
// Replace x with the state Id you want to add
$gameTroop.aliveMembers().forEach(enemy => enemy.addState(x));

If you're using an older version of MV that doesn't support ES6:
JavaScript:
$gameTroop.aliveMembers().forEach(function(member) {
    member.addState(x);
});
Thank you very much, it worked! 😤

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-add-and-remove-state-to-all-enemies-with-a-javascript-command.166992/