Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

TypeScript | String slice() Method with example

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The slice() is an inbuilt function in TypeScript which is used to extracts a section of a string and returns a new string. 
Syntax: 

string.slice( beginslice [, endSlice] )

Parameter: This method accept two parameter as mentioned above and described below: 

  • beginSlice – This parameter is the zero-based index at which to begin extraction.
  • endSlice – This parameter is the zero-based index at which to end extraction.

Return Value: This method returns the index of the regular expression inside the string. Otherwise, it returns -1. 

Below example illustrate the  String slice() method in TypeScriptJS:

Example 1: 

JavaScript




<script>
    // Original strings
    var str = "Geeksforgeeks - Best Platform"
  
    // use of String slice() Method
    var newstr = str.slice(0,14); 
  
    console.log(newstr);
</script>


Output: 

Geeksforgeeks

Example 2: 

JavaScript




<script>
    // Original strings
    var str = "Geeksforgeeks - Best Platform"
  
    // use of String slice() Method
    var newstr = str.slice(16); 
  
    console.log(newstr);
</script>


Output: 

Best Platform
My Personal Notes arrow_drop_up
Last Updated : 18 Jun, 2020
Like Article
Save Article
Similar Reads
Related Tutorials