title: Find Active Index From Array (Logic)
body: <p>I'm having a hard time with this one. I'm using Javascript.</p>
  
  <p>I have a textarea that's detecting the <code>@</code> input and storing it's position in an array.</p>
  
  <pre><code>var input = "@a @b @c" //textarea
  var indexes = [1, 4, 7];
  </code></pre>
  
  <p>Now on each new <code>input</code> I want to find out the active index by looking at the <code>caretPos</code></p>
  
  <pre><code>indexes.forEach(function(value, i){
      if (input.substr(value - 1, 1) !== '@') {
          indexes.splice(i, 1);
      }
      if (caretPos == value || caretPos &gt; value) {
          activeIndex = value;
      }
  }
  </code></pre>
  
  <p>I know I'm missing one check but I don't know how to implement. This code works as long as you're going backwards with the <code>caretPos</code> but once you go forward it stops working.</p>
  
  <p>Edit: In case its not clear. If the <code>caretPos</code> is <code>5</code> the <code>activeIndex</code> would be <code>4</code>.</p>