JavaScript slice() function extracts parts of a string and returns the extracted parts in a new string. Apply the start and end parameters to specify the part of the string you want to extract. The first character has position 0, the second has position 1, and so on.

Javascript string slice()

Javascript string slice() is an inbuilt function that extracts a part of a string and returns it as the new string without modifying an original string. We can use the startIndex and endIndex parameters to specify the part of the string you want to extract. The first character has position 0; the second has position 1, and so on. You can use the negative number to select from an end of the string.

The changes to the text in one string do not affect the other string.

Syntax

The syntax for the string slice method is the following.

string.slice(startIndex, endIndex)

#javascript #string.prototype.slice #js

Javascript String Slice Example | String.prototype.slice()
2.40 GEEK