What is the syntax of variable[i] doing?

I’m coming back to JavaScript after taking a few weeks off due to work… and I can’t quite remember what the syntax of having a variable, with square brackets and another variable inside of those brackets means, for example:

function countChar(string, ch) {
  let counted = 0;
  for(let i=0; i < string.length; i++) {
        if (string[i] == ch) {
            counted += 1;
        }
    }
    return counted;
}

What is

string[i]

doing in this character counter? Is it fetching something from the string that’s passed through the function?

what you want to look up here are javascript arrays. MDN is a good resource if you want to read the docs. Otherwise, you can re-do the portion of JS tutorials related to arrays to brush up on that topic.

I’ll do both, thanks! I might just go through the whole basic JS portion again for a refresher, can’t hurt.