Skip to content
Related Articles

Related Articles

Improve Article

TypeScript | String split() Method

  • Last Updated : 18 Jun, 2020
Geek Week

The split() is an inbuilt function in TypeScript which is used to splits a String object into an array of strings by separating the string into sub-strings.

Syntax:

string.split([separator][, limit])

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

  • separator – This parameter is the the character to use for separating the string.
  • limit – This parameter is the Integer specifying a limit on the number of splits to be found.

Return Value: This method returns the new array. 
Below examples illustrate the String split() method in TypeScript.
Example 1: 

JavaScript






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

Output: 

[ 'Geeksforgeeks', '-', 'Best', 'Platform' ]

Example 2: 

JavaScript




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

Output: 

[ 'G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's', ' ' ]

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it’s lowest price ever!




My Personal Notes arrow_drop_up
Recommended Articles
Page :