Javascript - Arrays


Hi, I'm a total noob when it comes to javascript - just started learning.
I came across this when learning about arrays:

Fun fact: You can also access each individual character in a string the same way you do with arrays. For instance, you can write:

var hello = 'Hello World';
// Output: W
'W' will be the output since it's the character in the 6th position. This works because JavaScript internally stores strings in a similar way that it stores arrays.

Why is the output W? I thought we count the spaces as well... cause if you find the length of the string 'Hello World', you get 11, meaning it counts the space...
This might be a dumb question haha but hopefully someone can explain why I don't count the spaces.

Thank you! :slight_smile:


we do count the space, but arrays are zero indexed based, which means the h is at index 0, not index 1. so the space is at index 5 and the w at index 6


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.