Suggest an editImprove this articleRefine the answer for “What does join() do?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**`join()`** is an array method that combines all its elements into one string, separating them with a specified separator (a comma by default). **Key point:** the method does not change the original array and always returns a string, not an array.Shown above the full answer for quick recall.Answer (EN)ImageThe `join()` method in JavaScript is used to **combine all array elements into one string**, separating them with a specified **separator**. --- ## Example: ```javascript const fruits = ["apple", "banana", "cherry"]; const result = fruits.join(", "); console.log(result); // "apple, banana, cherry" ``` - Each array element is turned into a string. - The separator `", "` is inserted between elements. - If no separator is specified, a **comma is used by default**. --- ## Syntax: ```javascript array.join(separator); ``` | Parameter | Description | |---|---| | `separator` | (optional) a string to insert between elements. If not specified, `","` is used. | --- ## A few examples: ### Without a separator: ```javascript [1, 2, 3].join(""); // "123" ``` ### With a space: ```javascript ["JS", "is", "awesome"].join(" "); // "JS is awesome" ``` ### With another character: ```javascript ["2025", "10", "14"].join("-"); // "2025-10-14" ``` ### With empty elements: ```javascript [1, , 3].join("-"); // "1--3" (the empty slot is still counted) ``` --- ## Important: - The method **does not change** the original array. - All elements are **implicitly converted to strings** before being joined. - Returns a **string**, not an array. --- ## Practical use example: ```javascript const tags = ["frontend", "javascript", "interview"]; const hashtagString = "#" + tags.join(" #"); console.log(hashtagString); // "#frontend #javascript #interview" ``` --- ## Summary: | What it does | Converts an array into a string | |---|---| | Default separator | `","` | | Returns | A string | | Changes the array | No | | Example | `["a", "b"].join("-") -> "a-b"` | --- > **In summary:** > `join()` is a way to **assemble an array into a string**, inserting the needed separator between elements.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.