JS Array Concat & Join


Array concat()

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Sanjay","Aman","Rehman"];
    
    var b = a.concat("rahul","Karan");

    document.write(b);
  </script>
</head>
<body>

</body>
</html>


Concat Two arrays

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Sanjay","Aman","Rehman"];
    var b = ["Rahul","Karan"];
    var c = a.concat(b);

    document.write(c);
  </script>
</head>
<body>
</body>
</html>


Concat multiple arrays

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Sanjay","Aman","Rehman"];
    var b = ["Rahul","Karan"];
    var d = ["Neha","Mahima"];
    var c = a.concat(b,d);

    document.write(c);
  </script>
</head>
<body>
</body>
</html>


Array join()

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Aman","Rehman","Karan"];
    var b = ["Rahul", "Sanjay"];
    var c = a.concat(b);
    document.write(c + "<br><br>");
    var d = c.join(" - ");
    document.write(d);
  </script>
</head>
<body>
</body>
</html>