Home Web Front-end JS Tutorial How to use join method

How to use join method

Feb 20, 2019 pm 04:34 PM
join

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])
Copy after login

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>
Copy after login

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>
Copy after login

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>
Copy after login

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 of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use JOIN in MySql How to use JOIN in MySql Jun 04, 2023 am 08:02 AM

How to use JOIN in MySql

What is the usage principle of MySQL Join? What is the usage principle of MySQL Join? May 26, 2023 am 10:07 AM

What is the usage principle of MySQL Join?

What are mysql's join query and multiple query methods? What are mysql's join query and multiple query methods? Jun 02, 2023 pm 04:29 PM

What are mysql's join query and multiple query methods?

How to use JOIN in MySQL How to use JOIN in MySQL Jun 03, 2023 am 09:30 AM

How to use JOIN in MySQL

Use MySQL's JOIN function to join tables Use MySQL's JOIN function to join tables Jul 26, 2023 am 08:37 AM

Use MySQL's JOIN function to join tables

How to optimize the join statement in MySQL How to optimize the join statement in MySQL Jun 03, 2023 am 09:31 AM

How to optimize the join statement in MySQL

Convert array to string using PHP join() function Convert array to string using PHP join() function Jun 26, 2023 pm 11:18 PM

Convert array to string using PHP join() function

How to improve performance through JOIN optimization in MySQL How to improve performance through JOIN optimization in MySQL May 11, 2023 am 08:48 AM

How to improve performance through JOIN optimization in MySQL

See all articles