JavaScript | string.slice()
The string.slice() is an inbuilt function in javascript which is used to return a part or slice of the given input string.
Syntax:
string.slice(startingindex, endingindex)
Parameter: This function uses two parameter startingindex( from which index, string should be started) and endingindex (before which index, string should be included) .
Return Values: It returns a part or a slice of the given input string.
Code #1:
<script> // Taking a string as input. var A = 'Ram is going to school'; // Calling of slice() function. 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); document.write(b +"<br>"); document.write(c +"<br>"); document.write(d +"<br>"); document.write(e); </script> |
chevron_right
filter_none
Output:
Ram i am is going to school is going to schoo going to school
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
- this in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



