Javascript - range of 5 around index in array
<p>I was wondering how to do the follow.</p>

<p>I have an array of objects and I'm trying to retrieve a set amount eg of them around a given index.</p>

<p>Here's an example.</p>

<pre><code>var arr = [0,1,2,3,4,5,6,7,8,9,10];
var index = 0;
var max = 5;

If the index is 0 I want [0 - 4]
If the index is 4 I want [2 - 6]
If the index is 9 I want [6 - 10]
</code></pre>

<p>But I also want it to work if the array is smaller then the max too. Eg </p>

<pre><code>var arr = [0,1,2];
var index = 0;
var max = 5;

Any index would return [0 - 2]
</code></pre>

<p>Any thoughts?</p>
