How to extend an existing JavaScript array with another array?

JavascriptWeb DevelopmentFront End Technology

To extend an existing array in JavaScript, use the Array.concat() method.

Example

You can try to run the following code to extend an existing JavaScript array with another array:

Live Demo

<html>    
   <head>      
      <title>JavaScript Array push Method</title>    
   </head>        
   <body>          
      <script>          
         var numbers = new Array(1, 4, 9);          
         var numbers2 = new Array(2, 5);                    
         numbers = numbers.concat(numbers2);                    
         document.write("new numbers is : " + numbers );                  
      </script>          
   </body>
</html>

Output

new numbers is : 1,4,9,2,5
raja
Published on 22-Apr-2018 22:22:34
Advertisements