Home > Article > Web Front-end > What does join mean in js
Question: What is the use of the join() method? Summary: The join() method concatenates array elements into a string. Use the specified character or string as the delimiter. In the resulting string, delimiters separate elements. Regular expressions can be used as delimiters.
join() method
join() method is used to join the elements in the array into a string , and uses the specified character as the delimiter.
Syntax
<code class="javascript">array.join(separator);</code>
Among them:
Return value
A string containing the concatenated array elements, separated by the specified character or string.
Usage
The join() method is usually used to convert an array into a string. For example:
<code class="javascript">const fruits = ["apple", "banana", "orange"]; const fruitsString = fruits.join(", "); // "apple, banana, orange"</code>
In the above example, the join() method joins the elements in the fruits array into a string using commas and spaces (" ") as delimiters.
Note
<code class="javascript">const numbers = [1, 2, 3, 4, 5]; const numbersString = numbers.join(/(?:,| - )/); // "1, 2 - 3, 4 - 5"</code>
The above is the detailed content of What does join mean in js. For more information, please follow other related articles on the PHP Chinese website!