title: How do I insert an array at an array specific index without removing existing data at specified index using angular
body: <p>I have a array, in that array I want to add another array on a particular index if the condition is met.</p>
  
  <p>This is my controller:</p>
  
  <pre><code>var app = angular.module('rulesApp');
  app.controller('myController2', ['$scope', '$rootScope'] {
        $scope.rows = function() {
          $rootScope.rows.push({
            id: $rootScope.input_columns.length,
            name: 'Name'
            dropped: false,
            dataType: '',
            type: 'input',
            path: ''
          }); //Json in which I need to add array
          //some code
          for (var i = 0; i &lt; cellValues.length; i++) {
            for (var j = 0; j &lt; $rootScope.input_columns.length; j++) {
              $rootScope.rows.splice(j, 0, cellValues); //I want to add
              cellValues array to rows Json on specified index
            }
          }
        });
  </code></pre>
  
  <p>Attaching image for initial object</p>
  
  <p><a href="https://i.stack.imgur.com/EzyIo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EzyIo.png" alt="enter image description here"></a></p>
  
  <p>After splice:</p>
  
  <p><a href="https://i.stack.imgur.com/F7Fly.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F7Fly.png" alt="enter image description here"></a></p>
  
  <p>Here I have a array of two elements, I want to add another array on a specified index with existing data too. for that I tried many solution then tried splice with <code>splice</code> it is removing existing index and adding new index. But I want that on the specified index I can add the array without overriding previous data. I tried using <code>$rootScope.rows[i].push(cellValues)</code> but it is giving <code>error: function not defined</code>.</p>
  
  <p>How can I insert array data in JSON without overriding the existing data. I have attached two screenshots for better understanding of the issue I am facing</p>
  
  <p>Is there any way that at specified index I can insert the <code>cellValue</code> array with existing data</p>
  
  <p>This is the structure being created after trying slice code. Now cell value array is created on 1-3 index then on 4th &amp; 5th index previous data is coming. But I want to add <code>cellValues</code> data to specified index itself with existing data.</p>
  
  <p><a href="https://i.stack.imgur.com/BwAWt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BwAWt.png" alt="enter image description here"></a></p>