String slice() method

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

Return a new string from the part of the string in betweenbeginwithendposition.

The original string is not changed.

endIs optional.

'This is my car'.slice(5) //is my car
'This is my car'.slice(5, 10) //is my

If the first parameter is set to a negative number, the starting index will start from the end, the second parameter must also be a negative number, and always count from the end:

'This is my car'.slice(-6) //my car
'This is my car'.slice(-6, -4) //my

Download mine for freeJavaScript beginner's manual


More js tutorials: