MV Using a variable to define event ID in script?

So lets say I wanted to type: "$gameMap.event(X).turnTowardPlayer();"
But instead of X being a number that defines the event ID have it be a variable that then defines the event ID, making it so the event in question can be changed on the fly by changing the variable. How would I do that?
JavaScript:
$gameMap.event($gameVariables.value(N)).turnTowardPlayer();

Original thread: https://forums.rpgmakerweb.com/threads/using-a-variable-to-define-event-id-in-script.179782/