Using splice with nested arrays in Javascript - Javascript Array Operation

Javascript examples for Array Operation:Array Nest

Description

Using splice with nested arrays in Javascript

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(){//from w  ww.  j  a  v  a  2s .  com
mainArray = new Array(new Array(1));

arraysToAdd = new Array(new Array(1,2), new Array(1,4), new Array(1,7), new Array(1,8));

console.log(arraysToAdd.length);

mainArray.splice.apply(mainArray, [0,1].concat(arraysToAdd));

console.log(mainArray.length);
    }

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

Related Tutorials