- String_Object: Please specify the valid string on which you want to perform Slicing.
- Start: Please specify the index position where the slicing will start.
- If you omit the first index then, Slicing will start from the beginning
- If you omit the second index then, Slicing will start from the first index position and continue to the last
- If you are using the Negative numbers as index then, string Slice function starts slicing from right to left
The following set of examples will help you understand the string function in Js Programming Language.
var Str1 = "Tutorial Gateway";
Following statement will slice the original string, starting at index position 2 and ends at index position 12
var Str2 = Str1.slice(2, 13);
var Str4 = Str1.slice(2);
Next, we used the negative indexing. Following statement will start slicing from -3 (index position of 3 from right to left) and ends at last position.
var Str6 = Str1.slice(-3);
Thank You for Visiting Our Blog