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.
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:
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!