How to use join method
Feb 20, 2019 pm 04:34 PMThe 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.
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('|')); } 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('')); } 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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What is the usage principle of MySQL Join?

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

Use MySQL's JOIN function to join tables

How to optimize the join statement in MySQL

Convert array to string using PHP join() function

How to improve performance through JOIN optimization in MySQL
