Let\'s say I have an array with data elements, in this example numbers, like this:
var a = [432, 238, 122, 883, 983];
And I want to limit t
You can also use Array.pop. Also if you wish to add a property to array, you can make it generic.
Array.prototype.Limit_push = function(x) {
this.unshift(x);
if (this.maxLength !== undefined && this.length > this.maxLength)
this.pop();
}
var a = [];
a.maxLength = 7
for (var i = 0; i < 10; i++) {
a.Limit_push(i);
console.log(a)
}
var b = [];
for (var i = 0; i < 10; i++) {
b.Limit_push(i);
console.log(b)
}