sql join 示例
JavaScript join()方法 (JavaScript join() method)
join() method is used to join array's elements into a string. It is called with an array and returns a string with the array elements.
join()方法用于将数组的元素连接成字符串。 使用数组调用它,并返回包含数组元素的字符串。
Syntax:
句法:
array.join([separator]);
Parameters: separator it is an optional parameter, which specify the separator between the array elements, it’s default value is comma.
参数: 分隔符,它是一个可选参数,它指定数组元素之间的分隔符,它的默认值为逗号。
Return value: A string containing array elements
返回值:包含数组元素的字符串
Example:
例:
Input:
var arr = [10, 20, 30, 40, 50];
Function call:
var str = arr.join();
Output:
str = "10,20,30,40,50"
JavaScript code to join array's elements into a string using Array.join() method
JavaScript代码使用Array.join()方法将数组的元素连接到字符串中
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var arr1 = ["Manju", "Amit", "Abhi", "Radib"];
var arr2 = [10, 20, 30, 40, 50];
var arr3 = [-10, -20, 0, 10, 20];
var str1 = arr1.join();
var str2 = arr2.join();
var str3 = arr3.join();
document.write("str1: " + str1 + "<br>");
document.write("str2: " + str2 + "<br>");
document.write("str3: " + str3 + "<br>");
document.write("printing the types of the objects...<br>");
document.write("type of arr1: " + typeof(arr1) + "<br>");
document.write("type of arr2: " + typeof(arr2) + "<br>");
document.write("type of arr3: " + typeof(arr3) + "<br>");
document.write("type of str1: " + typeof(str1) + "<br>");
document.write("type of str2: " + typeof(str2) + "<br>");
document.write("type of str3: " + typeof(str3) + "<br>");
</script>
</body>
</html>
Output
输出量
str1: Manju,Amit,Abhi,Radib
str2: 10,20,30,40,50
str3: -10,-20,0,10,20
printing the types of the objects...
type of arr1: object
type of arr2: object
type of arr3: object
type of str1: string
type of str2: string
type of str3: string
翻译自: https://www.includehelp.com/code-snippets/array-join-method-with-example-in-javascript.aspx
sql join 示例