Do you want to know how to split a string in TypeScript? In this Typescript tutorial, I will explain everything about the Typescript split string. Especially how to split strings in TypeScript using various methods.
To split a string in TypeScript, you can use the split() method, which divides the string into an array of substrates based on a specified separator. For more complex patterns, regular expressions can be used as separators. Additionally, you can limit the number of splits by providing a second argument to split().
Split string in TypeScript
Let’s explore various methods for splitting strings in TypeScript with examples.
Using the split() Method
The split() method in TypeScript is the most common way to divide a string into an array of substrings based on a specified separator. Here is an example of a TypeScript string split with complete code:
let text: string = "TypeScript is amazing!";
let words: string[] = text.split(" ");
console.log(words);
In this example, the string is split at each space, resulting in an array of words. You can see the output in the screenshot below:
Output:
[ 'TypeScript', 'is', 'amazing!' ]

When using split(), it’s important to consider edge cases. For instance, splitting an empty string returns an array with one empty string element, not an empty array. Additionally, handling cases where the separator is not found in the string is crucial to avoid unexpected results.
let text: string = "";
let result: string[] = text.split(",");
console.log(result); // [""]
text = "TypeScript";
result = text.split(",");
console.log(result);
You can see the output in the screenshot below:

Check out Split String by Length in Typescript
Split string with a Limit
You can also limit the number of splits by providing a second argument to the split() function in TypeScript. Here is a complete code for splitting a string in TypeScript.
let text: string = "TypeScript is amazing and versatile!";
let words: string[] = text.split(" ", 3);
console.log(words);
Here, the string is split into only the first three words. Check out the screenshot below for the output.

Read Split String By New Line in Typescript
Split a Typescript string with a Regular Expression
You also use the regular expression to split in TypeScript. Here is a complete code to split a string in TypeScript using a regular expression.
let text: string = "TypeScript, JavaScript, Python";
let languages: string[] = text.split(/,\s*/);
console.log(languages);
This splits the string at each comma, regardless of the number of spaces following it. Here is the output below; check the screenshot.
[ 'TypeScript', 'JavaScript', 'Python' ]

Check out Split String And Get Last Element In Typescript
Splitting and Mapping
Combining split() with map() allows for more sophisticated operations on each substring. Here is a complete code for the typescript split string.
let text: string = "1 SharePoint, 2 PowerApps, 3 Power Automate";
let numbers: number[] = text.split(", ").map(s => parseInt(s.split(" ")[0]));
console.log(numbers);
This extracts the number from each “number language” pair in the string. Here is the output you can check in the screenshot below:

Read Split String by Regex in TypeScript
Splitting with Destructuring
Destructuring can be used to capture specific parts of the split string into variables in TypeScript.
let text: string = "SharePoint:PowerApps:PowerBI";
let [first, second, third] = text.split(":");
console.log(first, second, third);
This assigns each language to a separate variable. You can see the output in the screenshot below:

Check out TypeScript Split String Into Array
Typescript split string by comma
Now, let us take another example of a TypeScript split string. I will show you how to split a string by a comma in TypeScript.
To split a string by a comma in TypeScript, you can use the split() method with a comma (,) as the separator. Here’s an example:
let csvData: string = "SharePoint, PowerApps, PowerBI";
let technology: string[] = csvData.split(", ");
console.log(technology);
Output:
[ 'SharePoint', 'PowerApps', 'PowerBI' ]
You can see the screenshot below:

Read How to Split String By Dot in TypeScript
TypeScript split string by character
To split a string by a specific character in TypeScript, you again use the split() method, specifying the character as the separator. Here’s an example where we split a string by a character -:
Here is the complete code to split a string by character in TypeScript.
let dateString: string = "2025-11-30";
let dateParts: string[] = dateString.split("-");
console.log(dateParts);
Output:
[ '2025', '11', '30' ]
Check out the screenshot below for the output also:

In this example, the string dateString representing a date is split at each hyphen (-), resulting in an array containing the year, month, and day as separate strings.
Read Split String With Multiple Separators In TypeScript
Typescript split string by slash
Here is another Typescript split string example. In this case, we will see how to split a string by a slash in TypeScript.
To split a string by a slash (/) in TypeScript, you can use the split() method with / as the separator. Here’s an example:
let filePath: string = "user/documents/photos/image.jpg";
let pathParts: string[] = filePath.split("/");
console.log(pathParts);

In this example, the string filePath representing a file path is split at each slash (/), resulting in an array containing the different parts of the path.
Typescript split string by semicolon
In Typescript, you can easily split a string by semicolon with a few lines of code. Here’s an example of splitting a string by a semicolon (;) in TypeScript:
let settings: string = "color:blue; size:medium; style:casual";
let options: string[] = settings.split("; ");
console.log(options);

In this example, the settings string, which contains key-value pairs separated by semicolons, is split into an array of individual settings. Each element in the options array represents one setting, like "color:blue".
Conclusion
In this tutorial, I explained how to split a string in TypeScript with various examples. You can split a string by spaces, commas, characters, slashes, or semicolons, etc. using the TypeScript split() method.
Here, we learned how to use the split() method in TypeScript to split a string with real examples.
You may also like the following tutorials:

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.