the most darndest thing! the following code prints out 'llo' instead of the expected 'wo'. i get such surprising results for a few other numbers. what am i missing here?
The code above is wrong because the first value is the start point to the end point.E.g move from char 5 which is o and go to char 2 which is the l so will get llo So you have told it to go backwards.
You're confusing substring() and substr(): substring() expects two indices and not offset and length. In your case, the indices are 5 and 2, ie characters 2..4 will be returned as the higher index is excluded.
var stringValue = 'Welcome to India';
// if you want take get 'India'
// stringValue.substring(startIndex, EndIndex)
stringValue.substring(11, 16); // O/p 'India'