Limit array size
<p>Let's say I have an array with data elements, in this example numbers, like this:</p>

<pre><code>var a = [432, 238, 122, 883, 983];
</code></pre>

<p>And I want to limit the array, so that everytime I add an element to the array, it always keeps a length of let's say 7, or less and removes the oldest elements.</p>

<p>My current aproach looks like this:</p>

<pre><code>function add(x) {
    a.unshift(x);
    a = a.slice(0, 7);
}
</code></pre>

<p>It works just fine, but isn't there a more elegant way to do it, like one line or something?</p>

<p>Edit:
By "more elegant" I mean so that I don't need the add function and just easily could inline the code where I need it, without typing out a for example three times, and only having one line would also make the code "clearer"</p>