JavaScript Array concat() method : The concat() method is used to join or combine the two or more arrays. It doesn't change the original array. It return the new array having all the elements of combined arrays.
Syntax of array concat() method :
array1.concat(array2, array3,..., arrayX)
Example of Array concat() method : Here I will show you how we can join the two or more arrays using the concat() method.
<!DOCTYPE html>
<html>
<body>
<p>To join two arrays click the button "join".</p>
<button onclick="joinLists()">join</button>
<p id="container"></p>
<script>
function joinLists() {
var list1 = ["Rahul", "Pramod"];
var list2 = ["John", "Manish", "Sumit"];
var students = list1.concat(list2);
document.getElementById("container").innerHTML = students;
}
</script>
</body>
</html>
Output :
Rahul,Pramod,John,Manish,Sumit
0 Comment(s)