Document directory
- Syntax
- Return Value
- Example 1
- Example 2
Definition and usage
The join () method is used to put all elements in the array into a string.
Elements are separated by the specified delimiter.
Syntax
arrayObject.join(separator)
| Parameters |
Description |
| Separator |
Optional. Specifies the delimiter to use. If this parameter is omitted, a comma is used as the separator. |
Return Value
Returns a string. This string is used to convert each element of arrayobject into a string, connect these strings, and insert them between two elements.Separator
String.
Example 1
In this example, we will create an array and put all its elements into a string:
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.join())
</script>
Output:
George,John,Thomas
Example 2
In this example, the elements in the array are separated using delimiters:
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.join("."))
</script>
Output:
George.John.Thomas