How to Join Elements of an Array in JavaScript
In this lesson, we will see how to join elements of an array in JavaScript, sometimes we want to join elements of an array in JavaScript with a separator so how can we do that?
The join() method
To do that we can use the join() method that returns the array as a string, in the example below we are using a comma as a separator.
const colors = ["blue", "orange", "black", "red"];
console.log(colors.join(","));
//blue,orange,black,red