JavaScript String slice() Method Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The slice() method in JavaScript is used to extract a portion of a string and create a new string without modifying the original string.Syntax:string.slice(startingIndex, endingIndex);Parameters: This method uses two parameters. This method does not change the original string.startingIndex: It is the start position and it is required(The first character is 0).endingIndex: (Optional)It is the end position (up to, but not including). The default is string length.Return Values:It returns a part or a slice of the given input string.Example 1: Slicing StringThe code slices the string "Geeks for Geeks" into three parts using the slice() method based on specified indices and logs each part separately. JavaScript let A = 'Geeks for Geeks'; b = A.slice(0, 5); c = A.slice(6, 9); d = A.slice(10); console.log(b); console.log(c); console.log(d); OutputGeeks for Geeks Example 2: Negative start or end index caseThe code slices the string "Ram is going to school" into multiple parts using the slice() method with various index combinations and logs each part separately. JavaScript let A = 'Ram is going to school'; // Calling of slice() Method b = A.slice(0, 5); // Here starting index is 1 given // and ending index is not given to it so // it takes to the end of the string c = A.slice(1); // Here endingindex is -1 i.e, second last character // of the given string. d = A.slice(3, -1); e = A.slice(6); console.log(b); console.log(c); console.log(d); console.log(e); OutputRam i am is going to school is going to schoo going to school Supported Browser:Google ChromeEdge FirefoxOperaSafari Comment More info S ShivamKD Follow Improve Article Tags : JavaScript Web Technologies javascript-string JavaScript-Methods Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings6 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in Javascript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readJavascript Scope3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like