create a string by joining the elements of an array in JavaScript
In this post we will give you information about create a string by joining the elements of an array in JavaScript. Hear we will give you detail about create a string by joining the elements of an array in JavaScriptAnd how to use it also give you demo for it if it is necessary.
Use the JavaScript join() method
You can easily create a string by joining the elements of an array using the JavaScript join() method. The join() method also allow you to specify separator to separate the array elements. The default separator is comma (,). Let’s take a look at the following example:
<!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 alert(colors.join()); // Outputs: red,green,blue alert(colors.join(", ")); // Outputs: red, green, blue alert(colors.join("-")); // Outputs: red-green-blue alert(colors.join(" + ")); // Outputs: red + green + blue alert(colors.join("")); // Outputs: redgreenblue </script> </body> </html>
Hope this and post will helped you for implement create a string by joining the elements of an array in JavaScript. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and Keep reading our blogs