What happends if you put a variable in a array


var hits = []
for(var i = 0; i < text.length; i++) {
    if (text[i] === 'j') {

what does text[i] do ?


text[i] accesses the ith index of text, for each iteration of the loop.

So on the first iteration it would be 0. The Second 1. And so forth until it meets the length of text.


From what I understood (somebody correct me if I'm wrong), text[i] simply returns the character of i.

So say I have a string "JavaScript", and 'S' belongs to i = 4. If I run text[4], it will return 'S'.



This is exactly right.