To convert a string to an array in TypeScript, use split() with a separator, such as "a,b,c".split(","), which returns a string[]. For an array of single characters, use Array.from(str) instead of split(""):
const cities = "Austin,Denver,Seattle".split(","); // string[]
const letters = Array.from("Texas"); // ["T","e","x","a","s"]
Here I’m compiling in strict mode with TypeScript 7.0.2 with Node.js v22.22.2, and each output block is pasted from the console.
You’ll see split() with strings and regular expressions, character arrays that don’t break emoji, strings of numbers, and JSON text that already holds an array.
Convert a string to an array with split()
split() cuts the string at every separator and returns the pieces. TypeScript types the result as string[] automatically:
const csvRow = "Austin,Denver,Seattle,Boston";
const cities: string[] = csvRow.split(",");
console.log(cities, cities.length);
const sentence = "Ship to Portland today";
console.log(sentence.split(" ")); // repeated spaces leave empty strings
console.log(sentence.trim().split(/\s+/)); // regex: any run of whitespace
console.log("".split(",")); // not an empty array!
console.log("a,b,c,d".split(",", 2)); // limit
Output:
[ 'Austin', 'Denver', 'Seattle', 'Boston' ] 4
[ 'Ship', 'to', '', '', 'Portland', '', 'today' ]
[ 'Ship', 'to', 'Portland', 'today' ]
[ '' ]
[ 'a', 'b' ]

Two traps show up here: double spaces create empty items, and splitting an empty string gives [""], not []. For CSV-style input with spaces after the commas, see splitting a string by comma in TypeScript.
How do I convert a string to an array of characters?
split(""), spread [...str] and Array.from(str) look the same on plain letters. Emoji and flags show the difference:
const word = "Texas";
console.log(word.split(""));
console.log([...word]);
console.log(Array.from(word));
const order = "Coffee โ x2 ๐บ๐ธ";
console.log(order.split("").length, "items from split('')");
console.log(Array.from(order).length, "items from Array.from");
console.log(order.split("").slice(-4));
console.log(Array.from(order).slice(-2));
Output:
[ 'T', 'e', 'x', 'a', 's' ]
[ 'T', 'e', 'x', 'a', 's' ]
[ 'T', 'e', 'x', 'a', 's' ]
16 items from split('')
14 items from Array.from
[ '\ud83c', '\uddfa', '\ud83c', '\uddf8' ]
[ '๐บ', '๐ธ' ]

split("") works on UTF-16 code units, so one emoji becomes two broken pieces. Spread and Array.from iterate by code point. A flag is still two code points, so it stays as two regional letters.
I default to Array.from() for characters. If you need the raw bytes instead, use converting a string to a byte array.
Convert a string of numbers to a number array
Values from a form or a URL arrive as one string. Split, then convert each piece with Number, and drop anything that isn’t a real number:
const prices = "19.99, 5.25, 102, abc";
const asNumbers: number[] = prices.split(",").map(Number);
console.log(asNumbers);
const clean = prices
.split(",")
.map((s) => Number(s.trim()))
.filter((n) => Number.isFinite(n));
console.log(clean, "total:", clean.reduce((a, b) => a + b, 0).toFixed(2));
const zip = "02134";
console.log(Array.from(zip, Number)); // map while converting
Output:
[ 19.99, 5.25, 102, NaN ]
[ 19.99, 5.25, 102 ] total: 127.24
[ 0, 2, 1, 3, 4 ]

Number(" 5.25") ignores surrounding spaces, but "abc" becomes NaN. More conversion rules are in converting a string to a number in TypeScript.
Convert a JSON string to an array with JSON.parse()
If the string is already JSON, don’t split it. JSON.parse() returns any, so give it a type, or better, check it at runtime:
const body = '["Chicago","Miami","Dallas"]';
const raw = JSON.parse(body); // type: any
const stores: string[] = JSON.parse(body); // annotate what you expect
function isStringArray(value: unknown): value is string[] {
return Array.isArray(value) && value.every((v) => typeof v === "string");
}
const checked: unknown = JSON.parse('["Reno", 42]');
console.log(stores.length, typeof raw);
console.log(isStringArray(checked) ? checked : "not a string[]: " + JSON.stringify(checked));
Output:
3 object
not a string[]: ["Reno",42]

The annotation alone doesn’t check anything, so I use a type guard for data from outside the app. There’s more in converting JSON to an array in TypeScript.
String to array methods in TypeScript compared
| Input | Use | Result |
|---|---|---|
"a,b,c" | s.split(",") | ["a","b","c"] |
| Words with uneven spaces | s.trim().split(/\s+/) | Words only |
| Characters (emoji-safe) | Array.from(s) or [...s] | One item per code point |
"1,2,3" | s.split(",").map(Number) | number[] |
| JSON text | JSON.parse(s) + type guard | Typed array |
Going the other way, from an array back to text, is covered in converting an array to a string in TypeScript.
For more string handling in TypeScript, start with these:
- Remove spaces from a string in TypeScript
- Reverse a string in TypeScript
- Remove empty strings from an array in TypeScript
- Combine an array of strings with join()
Frequently asked questions
How do I convert a string to an array in TypeScript?
Use str.split(separator), for example "a,b".split(","). The result is typed as string[].
How do I split a string into characters?
Use Array.from(str) or [...str]. split("") breaks emoji into two pieces.
Why does “”.split(“,”) return [“”]?
split() always returns at least one piece. Check for an empty string first, or filter out empty items.
How do I convert “1,2,3” to a number array?
Use str.split(",").map(Number), then filter with Number.isFinite to drop NaN.
What type does JSON.parse return in TypeScript?
It returns any. Annotate the variable or, safer, validate the value with a type guard.
Where is String.prototype.split documented?
See String.prototype.split() on MDN.
Bijay Kumar is a 13-time Microsoft MVP with more than 18 years in software development, and the founder of Python Guides and TSinfo Technologies. He started out building .NET and SharePoint solutions at HP, TCS and KPIT before moving into Python, machine learning and AI, and he also builds web apps with TypeScript and React. He writes the tutorials here himself, and every example is run before publishing so you see the real output. More about Bijay ยท Microsoft MVP profile ยท LinkedIn