Example 1 — Convert to a Comma-Separated String
Turn a color list into one line of text.
const colors = ["red", "green", "blue", "yellow"];
const text = colors.toString();
console.log(text);
// "red,green,blue,yellow" How It Works
- Start with four strings. Each element is already text.
- Call
toString(). Elements are joined with commas. - No spaces after commas. Result is
red,green,blue,yellow. - Array unchanged.
colorsstill has four items.

