Why do "for i in list" loops transfer to JS weird?

TL/DR: The python code for i in list translates to for (var stimName, _pj_c = 0, _pj_a = stimNames, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) { stimName = _pj_a[_pj_c]; in JS and I’m not sure if it’s playing a role in some of my errors. I think my main question is if this is normal and my backup question if it isn’t normal is whether this is related to other problems. Sorry for the mess you’re about to read.

URL of experiment: https://gitlab.pavlovia.org/lindsayas22/attentional-blink_exp-6

Description of the problem:

The code I wrote in Python in builder (in Begin Routine):

for stimName in stimNames:
    #starting a number to go through the while loop
    st = 0
    #while there's a dict entry for the stim type
    while stimuli[st][stimName]:
        #going through all stim types by hand bc treating a var as a name is bad
        if stimName == 'distractors':
            #getting entry
            row = stimuli[st][stimName]
            #appending current row to list of words
            st = st + 1

Which translated to JS as:

st = 0;
for (var stimName, _pj_c = 0, _pj_a = stimNames, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
    stimName = _pj_a[_pj_c];
    st = 0;
    while (stimuli[st][stimName]) {
        if ((stimName === "distractors")) {
            row = stimuli[st][stimName];
            st = (st + 1);

I defined stimuli and stimNames in two different code components for JS and Py because I was reading words from a .csv file, which can’t be translated properly. Both code components are in the same routine and listed before the code component that I wrote above. All of these happen in the setup section of my experiment, before anything actually happens. I’m showing these codes below for reference, but my issue is with the first for loop in the above code.

The Python code (in Begin Experiment):

file = 'C:/Users/.../html/resources/ABStimuli.csv'

stimNames = ['distractors', 'T1', 'T2', 'neutral', 'pleasant', 'unpleasant']
stimuliFile = data.TrialHandler(trialList= data.importConditions(file), nReps = 1, method='sequential', extraInfo= expInfo)

stimuli = stimuliFile.trialList

The JS code (also in Begin Experiment):

file = "ABStimuli.csv"

stimNames = ["distractors", "T1", "T2", "neutral", "pleasant", "unpleasant"];
stimuliFile = new TrialHandler({
    psychoJS: psychoJS,
    nReps: 1, method: TrialHandler.Method.SEQUENTIAL,
    extraInfo: expInfo, originPath: undefined,
    trialList: file,
    seed: undefined, name: 'stimuliFile'

stimuli = stimuliFile.trialList

Everything runs fine in builder, but I keep getting errors when I pilot it on Pavlovia. One of the errors (see this thread) said that a variable wasn’t defined and pointed me to the line in the script where I was defining it… It first happened with lists/arrays, so I just defined them as array = [] before the for loop and it was fine. But then it happened with the st = 0 that’s written inside the for loop in the first code, which I thought was weird because it shouldn’t have issues defining just a number like that right? So when I also put it outside the for loop, it worked fine, but then I got the same error for row = stimuli[st][stimName];. The fact that this only happens to variables being defined inside the for loops makes me feel like the issue is with the for loop itself, specifically, the fact that the for loop transfers to this

for (var stimName, _pj_c = 0, _pj_a = stimNames, _pj_b = _pj_a.length; (_pj_c < _pj_b); _pj_c += 1) {
    stimName = _pj_a[_pj_c];

Sometimes it’ll randomly give me a different error that ABStimuli.csv isn’t defined and I’m not sure if that means it only occasionally can’t read in the .csv file or if it randomly makes it past the definitions issue.

Sorry this post is such a mess. I don’t really know exactly what my question is, but something’s not working and I think it’s related to the way the for loop translates. If it’s not, then I wouldn’t mind some help with what is going wrong… I’ve been trying to figure out how to get this code from builder to Pavlovia for a solid week and a half now and am running out of ways to google/discourse search my issues :upside_down_face: