title: How to move to prev/next element of an array, reset index
body: <p>i have modify the code from the link below </p>
  
  <p><a href="https://stackoverflow.com/questions/12390626/how-to-move-to-prev-next-element-of-an-array">How to move to prev/next element of an array</a></p>
  
  <p>i like the second answer and understand the code, but i'm a beginner and i cannot work out how to reset the index so that every time it calls this function it cycles through the array. the poster said something about using a method to set the iterator to 0. could someone show me what the correct syntax should be. i would provide what i have done, but my sample code cannot be accepted. thanks</p>
  
  <p>thanks for your responses, i now understand what he meant by reset, but this is not what i wanted. i wanted to create a function that if i used a key it would move the array pointer and read me the item. if the pointer reached the end of the array it was meant to return to the beginning </p>
  
  <p>i modified one of the methods which is below, which is meant to set the iterator to 0 instead of returning false.</p>
  
  <p>arr.next = (function () { return (++cur &lt; this.length) ?this[cur] : cur=-1; });</p>
  
  <p>when i use this function it will cycle through the array, but between the end and the beginning it will return -1. is it possible to stop this from happening?  </p>