title: Drop last element of javascript array when array reaches specific length
body: <p>I would like to cache some data in javascript, but the cache should be limited to 10 elements for example.</p>
  
  <p>I can place the objects in javascript array, but what is the best way to keep the array limited to 10 elements?</p>
  
  <p>Example:</p>
  
  <pre><code>function getData(dataId) { return new NextDataObject(dataId); }
  
  var array = new Array();
  
  array.push(getData(0));
  array.push(getData(1));
  (...)
  array.push(getData(10)); // this should result in dropping "oldest" data, so getData(0) should be removed from the array, so that in array there are only 10 objects at maximum
  </code></pre>
  
  <p>Should such mechanism be written manually (using splice() for example?) or are there better ways to achieve such "cache" structure in javascript?</p>
  
  <p>BTW: in this particular situation I'm using angular.</p>