title: Push and Unshift Operation in javascript object
body: <p>I have the following dataset</p>
  
  <p><strong>Input:</strong></p>
  
  <pre><code>dataset[0]=[{data:29, color:"y"},{data:44, color:"g"}]
  dataset[1]=[{data:16, color:"r"},{data:23, color:"m"},{data:23, color:"b"}]
  </code></pre>
  
  <p>I am showing this information on bar chart, however bar chart attempting to group them. And it does not give me what I expect. <a href="http://jsfiddle.net/7dhb4jh0/1" rel="nofollow">http://jsfiddle.net/7dhb4jh0/1</a></p>
  
  <p>Therefore,I need to have the following output before I feed my bar chart</p>
  
  <p>The logic behind the desired output to match the length of two dataset by adding <code>{data:0, color:null}</code> There are two things involved <code>unshift</code> and <code>push</code> operations</p>
  
  <p><strong>Desired Output:</strong></p>
  
  <pre><code>dataset[0]=[{data:29, color:"y"},{data:44, color:"g"},{data:0, color:null},{data:0, color:null},{data:0, color:null}]
  dataset[1]=[{data:0, color:null},{data:0, color:null},{data:16, color:"r"},{data:23, color:"m"},{data:23, color:"b"}]
  </code></pre>
  
  <p><strong>Initial Attempt</strong></p>
  
  <p>I have did it as follows, <a href="https://jsfiddle.net/s8mywm33/1/" rel="nofollow">https://jsfiddle.net/s8mywm33/1/</a></p>
  
  <pre><code>dataset=[];
  dataset[0]=[{data:29, color:"y"},{data:44, color:"g"}]
  dataset[1]=[{data:16, color:"r"},{data:23, color:"m"},{data:23, color:"b"}]
  
  sum1=dataset[0].length
  sum2=dataset[1].length
  
  for(i=0;i&lt;sum1;i++)
  {
      dataset[1].unshift({data:0, color:null})
  }
  
  for(i=0;i&lt;sum2;i++)
  {
     dataset[0].splice(2, 0, {data:0, color:null});
  }
  
  console.log(dataset[0]);
  console.log(dataset[1]);
  </code></pre>
  
  <p>However is there a better way to do it?</p>