Array join

In this chapter you will learn:

  1. How to join array element together

Array join() method

The join() method accepts the string separator as the only argument and returns a string containing all items.

<!DOCTYPE html><!--   ja va 2  s  . c o  m-->
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
        var colors = ["red", "green", "blue"]; 
        document.writeln(colors.join(",")); //red,green,blue 
        document.writeln(colors.join("||")); //red||green||blue 
       
    </script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to add array together
Home » Javascript Tutorial » Array
Array Type
Array creation
Array type detecting
Array iterate
Array Length
Add to Array
Array join
Array concat()
Array every method
Array search from start with indexOf()
Array search from the end with lastIndexOf()
Array filter
Array mapping
Array forEach
Array pop and push
Array shift()
Array reduce()
Array reduceRight()
Array reverse()
Array slice()
Array some()
Array splice()
Array sort()
Array toString()
Array unshift()