-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12-joinMethod.js
More file actions
48 lines (31 loc) · 1.16 KB
/
12-joinMethod.js
File metadata and controls
48 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*JavaScript Array join() Method
The JavaScript Array join() Method is used to join the elements of an array into a string.
The elements of the string will be separated by a specified separator and its default value is a comma(,).
Syntax
array.join(separator);
Parameters
This method accepts a single parameter as mentioned above and described below:
separator: It is Optional i.e., it can be either used as a parameter or not.
Its default value is a comma(, ).*/
/*Example 1: In this example, the function join() joins together the
elements of the array into a string using ‘|’.*/
function func() {
let a = [1, 2, 3, 4, 5, 6];
console.log(a.join('|'));
}
func();
// Output
// 1|2|3|4|5|6
/*Example 2: In this example, the function join() joins together the elements
of the array into a string using ‘, ‘ since it is the default value.*/
let b = [1, 2, 3, 4, 5, 6];
console.log(b.join());
// Output
// 1,2,3,4,5,6
/*Example 3: In this example, the function join() joins together the elements of
the array into a string using ‘ ‘ (empty string).*/
let c = [1, 2, 3, 4, 5, 6];
console.log(c.join(''));
console.log(c.join(' '));
// Output
// 123456