MZ How do I set a variable to an enemy's ex-parameter?

I'm trying to set a variable to the hit rate for an enemy so I can use it for some dialogue outside of battle. However, while I can get the enemy's ex-parameter code (22):
Code:
$dataEnemies[1].traits[0].code;

and I can get the hit rate's dataId (0):
Code:
$dataEnemies[1].traits[0].dataId;

I can't figure out how to get anything for the hit rate (or any other ex-parameter), which I've set (as a test) to 35%.

I was able to figure out how to get the hit rate for my party leader as a whole number:
Code:
($gameParty.leader().hit * 100);

But I can't get any value other than 0 for an enemy that's in the database.

I've also tried:
Code:
($dataEnemies[1].hit * 100);
, and that returns 0 as well.

I'm not trying to change the hit rate or anything weird like that, I'm just using it for some dialogue with an NPC who wants to compare hit rates (and other ex-parameters) with the party leader.

Thank you.
and I can get the hit rate's dataId (0):
the trait property youre looking for is value
Code:
$dataEnemies[1].traits[0].value;

but also when youre taking the traits off of database objects, the order is as they appear in the trait list. unless you use a bit extra js to find the entry with a certain code or make sure that every enemy's nth trait is their hit rate trait, you might not grab the right one.

I was able to figure out how to get the hit rate for my party leader as a whole number:
additionally, that works for Game_Actors and Game_Enemies. not their data counterparts. the data entries only have the trait info. the parameters and the functions behind them only exist on the actual battlers
JavaScript:
for (const troop of $gameTroop._enemies) { //Checks every enemy
    if (troop._enemyId === hitChangeEnemyId) { //Change to the id of the enemy you want to change
        hitRateTrait = troop.enemy().traits.filter(trait => trait.code === 22 && trait.dataId === 0);
        if (hitRateTrait.length > 0) {
            hitRateTrait[0].value = $gameVariables.value(variableId); //1 = 100% so add division if needed
        }
    }
}

Put this in a Troop database battle event at turn 0 with Span: Battle.

Edit: I misread that post so bad omg I need to sleep.

Edit 2: HERE's the code you want
JavaScript:
$gameVariables.setValue(variableId, ($dataEnemies[1].traits.filter(t => t.code === 22 && t.dataId === 0)[0].value || 0)) //|| 0 incase of undefined
the trait property youre looking for is value
Code:
$dataEnemies[1].traits[0].value;
That was it! The Script Call Reference lists value1 and value2 as being what I needed, and I took that literally.

Also, the code that returns a whole number is
Code:
($dataEnemies[1].traits[0].value * 100);
since I'm assuming that actual value is stored as something like .35, just like it is with $gameParty.leader().hit

Thanks for your help!

EDIT:

And the code @LowrellLovelace suggested also works to pick out the correct trait in case the one I'm looking for isn't listed first in the enemy Traits as @Robro33 suggested. However, I refined it a bit so that it will return a whole number
Code:
$gameVariables.setValue(918, (($dataEnemies[1].traits.filter(t => t.code === 22 && t.dataId === 0)[0].value || 0)) * 100);

Thank you both!

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-set-a-variable-to-an-enemys-ex-parameter.182635/