TypeScript | String split() Method

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



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output: 

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

Example 2: 

JavaScript

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output: 

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

full-stack-img

My Personal Notes arrow_drop_up

Small things always make you to think big

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.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.