Javascript join () method

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.