If you checked to see if the array reached 10 records with array.length , just delete the first element before clicking on the new element. This can be done in several ways, as the Tushar states, array.shift() will be the fastest, but you can really use array.splice() .
It will look like this:
if(array.length > 10) { array.shift(); array.push(getData(10)); }
On a side note, instead of using var array = new Array() I suggest you just use var array = []; . This is because a new Javascript keyword sometimes has bad side effects. If, for example, you want to create an array with 1 element that is a digit, and you use var arr = new Array(12); , an array with 12 undefined elements will be created. While var arr = [12]; will create an array with 1 element, number 12.
But I guess this is a small thing to consider.
source share