Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions strings/array_to_stringVar
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var movie = new Array("Inception", "Prometheus", "Dark", "Oblivion", "Maleficient");
var string1= movie.join(); //join is a method which takes every element of array and convert it into a string ; every element of array is
//by default separated by ','.
document.write(string1);


OUTPUT:Inception,Prometheus,Dark,Oblivion,Maleficient

NOTE: we can also separate the array elements by our choice's separator instead of default separator ',' ; simply by passing that separator
as a parameter to join method in quotation mark.

eg:
var string1= movie.join("-");
document.write(string1);


OUTPUT:Inception-Prometheus-Dark-Oblivion-Maleficient