Example 1 — Default and Custom Separators
Omit the argument for commas, or pass your own separator.
const langs = ["JS", "Python", "Java"];
console.log(langs.join()); // "JS,Python,Java"
console.log(langs.join(" - ")); // "JS - Python - Java"
console.log(langs.join("|")); // "JS|Python|Java" How It Works
- Default comma. No argument → elements separated by
,. - Custom text.
" - "is inserted between each pair. - Any string works.
"|"is just another separator. - Array unchanged.
langsstill holds three items.

