String substring() method

Find out all the information about the JavaScript substring() method of strings

substring()Returns part of the string, similar toslice(), But there are some key differences.

If any parameter is negative, it is converted to0. If any parameter is greater than the length of the string, it is converted to the length of the string.

and so:

'This is my car'.substring(5) //'is my car'
'This is my car'.substring(5, 10) //'is my'
'This is my car'.substring(5, 200) //'is my car'
'This is my car'.substring(-6) //'This is my car'
'This is my car'.substring(-6, 2) //'Th'
'This is my car'.substring(-6, 200) //'This is my car'

Download mine for freeJavaScript beginner's manual


More js tutorials: