Could someone please explain what the .length
property is doing in the following code:
let sentenceCount = 0;
betterWords.forEach(word => {
if (word[word.length-1] === '.' || word[word.length-1] === '!') {
sentenceCount++;
}
});
I understand the basic idea of what .length
does, but when I try to print out word[word.length]
, it prints out as undefined
. If I print out word[word.length-1]
, then I get the .
and !
in the text. I'm not understanding what word[word.length-1]
actually is so that when -1
is attached it gets the characters on the end.
Thank you in advance for any advice on this.