Home  >  Article  >  Web Front-end  >  How to use join() method

How to use join() method

青灯夜游
青灯夜游Original
2019-02-20 14:13:573175browse

The join() method in JavaScript is used to put all the elements in the array into a string, which is separated by a specified delimiter.

How to use join() method

JavaScript join() method

Function: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)

separator: Specify the separator to use; can be omitted, if omitted, a comma is used as the separator.

Return value: Returns a string. The string is generated by converting each element of the arrayObject to a string and then concatenating the strings by a delimiter (a delimiter is inserted between the two elements).

JavaScript join() method usage example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文网(php.cn)</title> 
</head>
<body>
<script type="text/javascript">
    var arr = new Array(3)
    arr[0] = "George"
    arr[1] = "John"
    arr[2] = "Thomas"
    console.log(arr.join());
    console.log(arr.join("-"));
</script>
</body>
</html>

Rendering:

How to use join() method

The above is the entire content of this article, I hope it will be helpful to everyone's study.

The above is the detailed content of How to use join() method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn