Combining two arrays with different number of elements with nested for loop - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Combining two arrays with different number of elements with nested for loop

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){// w  w w.  j a  v a  2 s.co  m
var x = [1, 2, 3];
var y = ['a', 'b'];
var newarr = [];
for(var i=0;i<x.length;i++){
 for(var j=0;j<y.length;j++){
     newarr.push(x[i]+y[j]);
 }
}
console.log(newarr);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials