Intro to JavaScript Arrays join()

join() example

The array join() method combines all of the string elements in an array and returns a single string:

// as a reminder, movies is ['Barbie', 'Arrival', 'Get Out', 'Coco']
let movieString = movies.join();
// movieString is 'Barbie,Arrival,Get Out,Coco'

As you can see, by default, the movie strings were separated by a comma. However, we can pass join() whatever string we want to use as the separator:

movieString = movies.join(' -- ');
// movieString is 'Barbie -- Arrival -- Get Out -- Coco'