I have an array to have a maximum of 10 elements. Whenever I add a new element, if it already has 10, it would remove the first and push a new one.
I made this:
Array.prototype.pushMax = function(value,max){
if (this.length >= max){
this.shift();
}
this.push(value);
}
Which seems to work fine, however, I'm just wondering if there is a better way to do it (perhaps some native JavaScript function)