title: How do I avoid looping through an array to find a partial match?
body: <p>I am looping through an array of english phrases, and if i find a match, with the current text node, i replace it with it's translation in the non_english array. All of that works 100% for exact matches.</p>
  
  <p>But for partial matches, I need to use the .match command, which allows for partial matches.</p>
  
  <p>My code to search for exact matches is like this:</p>
  
  <blockquote>
    <p>var found = $.inArray(value,en_lang);</p>
  </blockquote>
  
  <p>Then if there is a found value, then do replacement of text. This method is fast and I love it.</p>
  
  <p>However to do partial word/phrase matching, I have to use this looping code.</p>
  
  <pre><code>// loop thru language arrays
  for (var x = en_count; x &gt; 0; x--) {
  
  // assign current from/to variables for replace
  var from = en_lang[x];
  var to = other_lang[x];
  
  // if value match do translation
  if (value.match(from)) {
      content(node, value.replace(from, to));
  }
  
  // mark this node as translated
  if ($.browser.msie == 'false') {
      $(node).data('translated', 'yes');
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This does the job but is pretty slow. After a lot of research, I have found that I can convert the english array to a list-based string via the join command.</p>
  
  <p>But I am unable to come up with a function to search this list for a partial match, and return the position in the list.</p>
  
  <p>I was trying out this old js function created in 2006. But I can't figure out how to get the position back, correctly.</p>
  
  <pre><code>function listfind(list, value, delimiters) {
  
      if (!delimiters) {
          var delimiters = ','
      }
  
      _TempListSplitArray = list.split(delimiters)
  
      var FoundIdx = 0;
  
      for (i = 0; i &lt; _TempListSplitArray.length; i++) {
          if (_TempListSplitArray[i] == value) {
              FoundIdx = i + 1;
              break
          }
          if (value.match(_TempListSplitArray[i])) {
              FoundIdx = i + 1;
              break
          }
      }
      return FoundIdx
  }
  </code></pre>
  
  <p>Thank you for your time. </p>