Categories
JavaScript Answers

How to add spaces between array items in JavaScript?

Spread the love

To add spaces between array items in JavaScript, we use the join method.

For instance, we write

const showtimes = ["1pm", "2pm", "3pm"];
const showtimesAsString = showtimes.join(", ");

to call showtimes.join with ', ' as the delimiter between each string in showtimes.

Therefore, showtimesAsString is "1pm, 2pm, 3pm".

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *