JavaScript Joining array elements in a string


Example

To join all of an array's elements into a string, you can use the join method:

console.log(["Hello", " ", "world"].join("")); // "Hello world"
console.log([1, 800, 555, 1234].join("-")); // "1-800-555-1234"

As you can see in the second line, items that are not strings will be converted first.