javascript get string from array with space between 1

javascript get string from array with space between

var showtimes = ["1pm", "2pm", "3pm"];
var showtimesAsString = showtimes.join(', '); // gives "1pm, 2pm, 3pm"

Here is what the above code is Doing:
1. We create an array called showtimes.
2. We create a variable called showtimesAsString.
3. We use the join() method to join the elements of the showtimes array into a string.
4. We pass the join() method a comma and a space as an argument.
5. The join() method returns a string of the elements of the showtimes array separated by a comma and a space.
6. We assign the returned string to the showtimesAsString variable.

Similar Posts