Length starts from 0, yes?

Length starts from 0, yes?
0

#1

#1


See, the output here is ‘‘e’’, but why? it says u have to count from 0, so in this case it should be ‘‘v’’…hm


#2

The length of an empty string ("") is 0. Length is the number of characters in the string (or items in the array).


#3
const str = 'abcde';

str[0]; // a
str[1]; // b
str[2]; // c
str[3]; // d
str[4]; // e

str.length; // 5

str[str.length - 1]; // e
str[str.length - 2]; // d
str[str.length - 3]; // c
str[str.length - 4]; // b
str[str.length - 5]; // a

The math all adds up.

See fencepost error for an explanation if you’re still confused. You can think of array/string indexes as fence panels and array/string lengths as the ending fence posts.