Iterating through an array

Iterating through an array
0

#1

I’m trying to iterate through an array an then trying to get the length but my code isn’t working. Why can’t get get the length?

var str = "The quick brown fox";
str = str.split(' ')

for (var i=0; i < str.length; i++) {
   console.log(str[i]);
   str[i].length()
}

TIA,

Gabriel


#2

The semi-colon is missing in the end of str[i].length; in the for loop.
Same at the begining, str = str.split(’ '); .


#3

Remove round brackets in this line:
str[i].length() should be str[i].length


#4

It’s totally fine to omit semicolons. https://standardjs.com/rules.html#semicolons


#5

I added the semi-colon and it still doesn’t work.


#6

Look at the comment by @Nnutthowze The extra parentheses at the end of length need to be removed if you have not done so already. Once you have removed those, the console will show the following after running code:
The
quick
brown
fox
=> 3


#7

After you split your array, look at the output: console.log(str);

And think how would you enumerate each content of the array.

GL!