Javascript Array Concat() Function

The Concat() function of array object is concatenates simple string values or one array with another existing array, and returns the new array. When concatenates two values and that are strings or numbers, their actual values are added to the returned array. When values to concat are object references, the same object reference will be added and not object itself. Use it for example to combined two array.

Javascript Array Concat() Function Example1

<!DOCTYPE html>
<html>  
<head>
  <!-- www.techstrikers.com -->
  <title>Javascript concat Method of Array Object</title>
<script type="text/javascript">  
function showConcate()  
{  
    var sweet_fruits = ["Mango", "Banana"];  
    var citric_fruits = ["Lemon", "Orange"];  
  
    //Way to concate array  
    document.write(sweet_fruits.concat(citric_fruits));   
  
    //Another way to concate array  
    document.write(sweet_fruits.concat("Grapes", ["Apple", "Kivi"]));   
}  
</script>  
</head>  
<body onLoad="showConcate()">  
</body>  
</html>

Javascript Concat Array Method Example2

<!DOCTYPE html>
<html>  
<head>
  <!-- www.techstrikers.com -->
  <title>Javascript concat Method of Array Object</title>
<script type="text/javascript">  
function showConcate()  
{  
    var maX=[6,1]  
    var miN=[10,20]  
    document.write(Math.max.apply(Math, maX.concat(miN)));  
}  
</script>  
</head>  
<body onLoad="showConcate()">  
</body>  
</html>