Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk2 min

How to Convert an Array to a String in TypeScript

Convert an array to a string in TypeScript with join(). Choose a delimiter, handle empty and nullish values, and format object arrays explicitly.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Array.prototype.join() to turn an array into a string in TypeScript. Pass a separator to control how the items appear: colors.join(', ') produces red, blue, green. The conversion runs at JavaScript runtime; TypeScript checks the types used in your code.

Use join() to choose the separator

join() returns a string containing the array elements, with the chosen separator between them. If you omit the separator, it uses a comma.

As an Amazon Associate I earn from qualifying purchases.

const colors: string[] = ['red', 'blue', 'green'];
const text = colors.join(', ');
// "red, blue, green"

TypeScript infers that text is a string, so an explicit : string annotation is unnecessary. Array types such as string[] describe the values at compile time; the conversion itself uses JavaScript’s array method. See the TypeScript Handbook for array type forms and primitive types.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a separator that fits the output you need:

Code Result
['red', 'blue'].join() red,blue
['red', 'blue'].join(', ') red, blue
['red', 'blue'].join(' | ') red | blue
['red', 'blue'].join('') redblue

The separator appears between elements, not after the last element. An empty array joined with any separator returns an empty string. MDN’s join() reference documents the method and its default comma separator.

What happens with empty, nullish, or nested values?

In a joined string, null, undefined, and empty array slots become empty fields—not the literal words null or undefined.

const values: (string | null | undefined)[] = ['a', null, undefined, 'b'];
values.join(', ');
// "a, , , b"

Nested arrays are converted recursively. The outer separator applies between the outer elements; nested arrays use commas internally, so their structure can look flattened in the resulting text.

Rank #2
TypeScript Programming Language - Software Engineer & Coder T-Shirt
  • TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
  • TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
  • Lightweight, Classic fit, Double-needle sleeve and bottom hem
[[1, 2], [3, 4]].join(';');
// "1,2;3,4"

These behaviors, including empty slots and nested arrays, are described in MDN’s method reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Format object arrays by selecting the fields you want

Joining objects directly usually does not produce useful labels. Map each object to the field intended for display, then join those strings.

type User = { name: string };
const users: User[] = [{ name: 'Ada' }, { name: 'Lin' }];
const names = users.map(user => user.name).join(', ');
// "Ada, Lin"

This makes the desired representation explicit instead of relying on default object coercion.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should you use toString() instead?

For arrays, toString() produces the default comma-separated form: it calls join() without an argument. Use join() when you need to choose the delimiter or make that formatting choice clear in the code. String(array) also gives the default string conversion, so neither is a substitute for a deliberately formatted display string.

A display string is not necessarily a serialization format. If another system needs structured data, choose a format designed for that requirement rather than assuming comma-separated output preserves the array’s structure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The TypeScript Handbook recommends lowercase primitive type names such as string rather than the special built-in type String. See Everyday Types.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.