What happends if you put a variable in a array


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

```

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

what does text[i] do ?

<do not remove the three backticks above>

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