Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Create String by Joining Array Elements</title> </head> <body> <script> // Sample array var colors = ["red", "green", "blue"]; // Joining array elements document.write(colors.join() + "<br>"); // Prints: red,green,blue document.write(colors.join(", ") + "<br>"); // Prints: red, green, blue document.write(colors.join("-") + "<br>"); // Prints: red-green-blue document.write(colors.join(" + ") + "<br>"); // Prints: red + green + blue document.write(colors.join("")); // Prints: redgreenblue </script> </body> </html>