join()
methodYou 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>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Check for a Hash (#) in a URL using JavaScript
Use the Window.location Property You...How to animate the opacity of an element on mouse hover using jQuery
Use the jQuery animate() method You c...PHP 7 - Upload Files & Images with Example Tutorials
This is a step by step PHP 7 file upload...How to get Next Previous Records in Laravel7.x with Example
We all ken that, Laravel is propagating...Use PHP Code into Laravel Blade
in this article, I will share with you h...