Last modified: Jul 29, 2026

JavaScript Array to String

Arrays are a core part of JavaScript. You often need to turn them into strings.

This is useful for displaying data, logging, or sending it to a server.

JavaScript gives you several ways to do this. Each method has its own use case.

We will cover the most common ones: toString(), join(), and JSON.stringify().

By the end, you will know which method to use and when.

Using toString()

The simplest way is the toString() method. It is available on every array.

It converts the array to a string. It separates elements with a comma.

This method works well for simple arrays of strings or numbers.


// Example using toString()
const fruits = ['Apple', 'Banana', 'Cherry'];
const result = fruits.toString();

console.log(result);
// Output: "Apple,Banana,Cherry"

Apple,Banana,Cherry

Important:toString() does not change the original array. It returns a new string.

It also works with nested arrays, but it flattens them only one level.


// Nested array example
const nested = [1, [2, 3], 4];
console.log(nested.toString());
// Output: "1,2,3,4"

1,2,3,4

Using join()

The join() method gives you more control. You can specify a separator.

If you do not provide a separator, it uses a comma by default.

This is perfect for creating readable lists or CSV data.


// Example using join() with a custom separator
const colors = ['Red', 'Green', 'Blue'];
const result = colors.join(' - ');

console.log(result);
// Output: "Red - Green - Blue"

Red - Green - Blue

You can also use an empty string to join all elements without any separator.


// Using empty separator
const letters = ['H', 'e', 'l', 'l', 'o'];
const word = letters.join('');
console.log(word);
// Output: "Hello"

Hello

Important:join() is great for creating strings from arrays of numbers or strings. It works well with any array type.

For more complex array operations, check out our JavaScript Array Methods Guide.

Using JSON.stringify()

When you need to convert an array to a JSON string, use JSON.stringify().

This method is best for sending data to an API or storing it in a file.

It preserves the structure of the array, including nested arrays and objects.


// Example using JSON.stringify()
const users = [
  { name: 'Alice', age: 25 },
  { name: 'Bob', age: 30 }
];
const jsonString = JSON.stringify(users);

console.log(jsonString);
// Output: '[{"name":"Alice","age":25},{"name":"Bob","age":30}]'

[{"name":"Alice","age":25},{"name":"Bob","age":30}]

Important:JSON.stringify() is not for display. It is for data interchange.

If you want to convert an array of objects to a readable string, use join() or a loop. For a deep dive, see our JavaScript Array of Objects Guide.

Handling Null and Undefined Values

Arrays can contain null or undefined values.

toString() and join() convert null and undefined to empty strings.


// Handling null and undefined
const mixed = [1, null, 2, undefined, 3];
console.log(mixed.toString());
// Output: "1,,2,,3"

1,,2,,3

JSON.stringify() removes undefined values and keeps null as null.


// JSON.stringify with null and undefined
const data = [1, null, 2, undefined, 3];
console.log(JSON.stringify(data));
// Output: '[1,null,2,null,3]'

[1,null,2,null,3]

Be aware of these differences when choosing your method.

Performance Considerations

For small arrays, performance is not a big issue.

For very large arrays, join() is usually faster than toString().

JSON.stringify() is slower because it does more work.

Use join() for large arrays when you need a custom separator.

Always test with your own data if performance matters.

Knowing the length of your array helps. See our JavaScript Array Length Guide.

Common Use Cases

Displaying a list: Use join(', ') to create a readable list.

Creating CSV: Use join(',') for simple CSV data.

Sending data to a server: Use JSON.stringify().

Logging for debugging: Use toString() or JSON.stringify().

Building a URL query string: Use join('&') with key-value pairs.

Each method has a specific purpose. Choose wisely.

Conclusion

Converting a JavaScript array to a string is easy.

Use toString() for quick comma-separated strings.

Use join() for custom separators and better control.

Use JSON.stringify() for data interchange.

Always consider the content of your array.

Handle null and undefined values carefully.

Now you can convert arrays to strings with confidence.

Practice with your own examples to master these methods.