Counting enemies & actors with "Attack Element"

Got a slight scripting problem, in that I have no idea how to do this.

I need two script statements. I'll write what I need below, in pseudo-code:

1) GET how many enemies, out of all enemies present, have "Attack Element == 1"

2) GET how many actors, out of all actors present, have "Attack Element == 2"

Can someone clarify how to do these? I assume it's going to involve filtering to get an array, and then performing a check on the length of that array... but I'm not certain how to structure it in the syntax.

This is because for a battle scenario, I need to count how many "fire enemies" are onscreen, or "ice actors" for a given moment. Previously I was doing this by incrementing a variable by 1 each spawn, and decrementing it by 1 on-death - but that has resulted in problems that make me think a cleaner solution is preferable.

I have a few other questions relating to this, where I'm looking to replace some of my more torturous logic with this kind of stuff... But I'll start with this one. I might be able to work the others out once I have this.
Code:
$gameTroop.aliveMembers().filter(function (battler) {
  return battler.attackElements().contains(ELEMENTID);
});
This will give you all enemies that has the ELEMENTID attack element. Change $gameTroop to $gameParty to get actors instead of enemies. Basically what filter function does is if the returned value isn't true, it will be removed from the array.
Code:
$gameTroop.aliveMembers().filter(function (battler) {
  return battler.attackElements().contains(ELEMENTID);
});
This will give you all enemies that has the ELEMENTID attack element. Change $gameTroop to $gameParty to get actors instead of enemies. Basically what filter function does is if the returned value isn't true, it will be removed from the array.
So...
Code:
$gameTroop.aliveMembers().filter(function (battler) {
  return battler.attackElements().contains(ELEMENTID);
}).length;
Will adding that give me the length of the array? Sorry, I'm still new to Javascript.
Yup.
Here's the rundown:
Code:
$gameTroop.aliveMembers()
Get all alive battlers (in this case enemies), will return an array.
Code:
.filter(function (battler) {})
Filter an array based on the returned value of the function.
Code:
battler.attackElements()
Return an array containing all battler attack element IDs.

Original thread: https://forums.rpgmakerweb.com/threads/counting-enemies-actors-with-attack-element.103475/