JavaScript String slice() MethodLast Updated : 17 Mar 2025 The JavaScript string slice() method is used to fetch the part of the string and returns the new string. It required to specify the index number as the start and end parameters to fetch the part of the string. The index starts from 0. This method allows us to pass a negative number as an index. In such case, the method starts fetching from the end of the string. It doesn't make any change in the original string. SyntaxThe slice() method is represented by the following syntax: Parameterstart - It represents the position of the string from where the fetching starts. end - It is optional. It represents the position up to which the string fetches. In other words, the end parameter is not included. ReturnPart of the string JavaScript String slice() Method ExampleLet's see some simple examples of slice() method. Example 1Here, we will print the part of the string by passing starting and ending index. Output: vat Example 2Here, we will provide starting index only. In such case, the method fetches the string up to its length. Output: TpointTech Example 3This is one more example where we provide only the starting index. Output: tpoint Example 4In this example, we will provide negative number as an index. In such case, the method starts fetching from the end of the string. Output: point Example 5In this example, we will provide negative number as a starting and ending index. In such case, the method starts fetching from the end of the string. Output: poin Next TopicJavaScript String |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India