- var newStr = str.substring(4,10)
- The message box would display the string "Script"
Unlike substring(), the substr() function's second argument is optional. In this argument, you enter a number that indicates the length of the desired snippet. With this in mind, to generate the same results as our previous code using this method, we'd use:
- var newStr = str.substring(4,6)