Program to use JavaScript Array join() method
let a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
let b = a.join(" ");
console.log(b);
Output
Cat Dog Tiger Lion Elephant
Steps Description
- Declare two variable
a
andb
- Initialize two variable
a
andb
with value of arraya = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant']
andb = a.join(" ")
- The
array join()
method joins the given statement to all elements of the array. - The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array join() method
let c = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night'];
let d = c.join(" * ");
console.log(d);
Output
Good Morning * Good Afternoon * Good Evening * Good Night
Steps Description
- Declare two variable
c
andd
- Initialize two variable
c
andd
with value of arrayc = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night']
andd = c.join(" * ")
- The
array join()
method joins the given statement to all elements of the array. - The value of
d
variable is displayed with the help of console.log inbuilt function