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

How to use join method

不言
不言Original
2019-02-20 16:34:383654browse

The Array.join() function is used to join the elements of the array into a string. Let's take a closer look at the specific usage of the Array.join() function.

How to use join method

Let’s first take a look at the basic syntax of the Array.join() function

Array.join([separator])

separator represents each element used to separate the array. A string of elements. If keeping the default array elements, separate them with commas (,).

This function returns a string created by concatenating all elements of the array using delimiters. If no delimiter is provided, the array elements are concatenated using comma (,) as it is the default delimiter for this function. If an empty string is provided as the delimiter, the elements will be concatenated directly without any characters between them. If array is empty, this function returns an empty string.

Let’s look at specific examples

Example 1:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
  var a = [ 1, 2, 3, 4, 5, 6 ]; 
  document.write(a.join(&#39;|&#39;)); 
} 
func(); 
</script>
</body>
</html>

The output results are as follows: 1|2|3| 4|5|6

Example 2:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
var a = [ 1, 2, 3, 4, 5, 6 ]; 
document.write(a.join()); 
} 

func(); 
</script> 

</body>
</html>

The output result is as follows: 1,2,3,4,5,6

Example 3:

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
var a = [ 1, 2, 3, 4, 5, 6 ]; 
document.write(a.join(&#39;&#39;)); 
} 
func(); 
</script> 
</body>
</html>

The output result is as follows: 123456

This article has ended here, you can pay attention to more exciting content Other related column tutorials on php Chinese website! ! !

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