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?