How to merge two arrays in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To merge two arrays in JavaScript, use the Array.concat() method. JavaScript array concat() method returns a new array comprised of this array joined with two or more arrays.

Example

You can try to run the following code to merge two arrays:

Live Demo

<html>    
   <head>      
      <title>JavaScript Array concat Method</title>    
   </head>      
   <body>          
      <script>          
         var alpha = ["a", "b", "c"];          
         var numeric = [1, 2, 3];  
         var alphaNumeric = alpha.concat(numeric);          
         document.write("alphaNumeric : " + alphaNumeric );        
      </script>          
   </body>
</html>

Output

alphaNumeric : a,b,c,1,2,3
raja
Published on 22-Apr-2018 18:48:39
Advertisements