Don't quite understand the last position in a substring


#1


console.log("January".substring(0,3));

If I want jan as the output, why is the second position in the substring 3? If I count from 0 the N in would be 2...


#2

jan has the following indexes: 0, 1 and 2. and substring works for values lesser then (<) the stop value (in your case 3)


#3

Sorry, still don't understand. Why is the stop value 3?


#4

because you want to get jan which are at the following indexes: 0, 1 and 2

so you need a stop value of 3, because the stop value is not included


#5

Oh, didn't realize the stop value wasn't included thanks!


#6

that was also in my original answer, what do i need to improve upon on my first answer?


#7

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