What happends if you put a variable in a array


#1



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

what does text[i] do ?


#2

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.


#3

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'.


#4

@trishajeane

This is exactly right.