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
Just adjust the length property after pushing.
function add(x) { a.unshift(x); a.length = a.length < 7 ? a.length : 7; }
The cleanes way is to check before
function add(x) { a.unshift(x); if (a.length > 7) { a.length = 7; } }