Using mod to wrap around
<p>Assume the array has a length of 1000. I am trying to create a simple way to traverse the image paths stored in the array without going out of bounds. The method below handles the wrap around using modulus well when it comes to clicking the 'next' button to increment array index, but not when I have to decrement and deduct one from the index  (when the user clicks the previous button).</p>

<p>Basically what I am trying to do is:</p>

<pre><code>998 -&gt; click next -&gt; 999
999 -&gt; click next -&gt; 0
0 -&gt; click previous -&gt; 999
</code></pre>

<p>My Javacript</p>

<pre><code>var index = 0;

$('.catalog-img-container').attr("src", javascript_array[index]);
$(".next").click(function(){
        $('.catalog-img-container').attr("src", javascript_array[++index%arrayLength]);
    });         
$(".previous").click(function(){
    $('.catalog-img-container').attr("src", javascript_array[--index]);
    alert(index);
</code></pre>

<p>I appreciate any help with</p>

<p>Many thank in advance.</p>
