title: Javascript get specific values from array list
body: <pre><code>&lt;select name="List" id="List"&gt;
      &lt;option value=""&gt;-Select-&lt;/option&gt;
      &lt;option value=""&gt;--Product--&lt;/option&gt;
      &lt;option value=""&gt;product1&lt;/option&gt;
      &lt;option value=""&gt;product2&lt;/option&gt;
      &lt;option value=""&gt;product3&lt;/option&gt;
      &lt;option value=""&gt;--Software--&lt;/option&gt;
      &lt;option value=""&gt;software1&lt;/option&gt;
      &lt;option value=""&gt;software2&lt;/option&gt;
      &lt;option value=""&gt;software3&lt;/option&gt;
      &lt;option value=""&gt;--Services--&lt;/option&gt;
      &lt;option value=""&gt;service1&lt;/option&gt;
      &lt;option value=""&gt;service2&lt;/option&gt;
      &lt;option value=""&gt;service3&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>I have the above List on my HTML select field.</p>
  
  <p>I want to be able to get only the values --Product--, --Software--, --Services--
  So I created an loop to go throw the list of products and used the method startwith to pickup the values starting with "--".</p>
  
  <pre><code>function loadFilter() {
    var x = document.getElementById('List');
    var i;
    var n;
    for (i = 0; i &lt; x.length; i++) {
      str = x[i].text
      var n = str.startsWith('--');
      flag = true;
      if (n == true) {
        alert(x[i].text);   // list --Product--, --Software--, --Services--
        alert(x[3].text);   // prints from the LIST &lt;product1&gt; and not &lt;--Services--&gt;
      }
    }
  }
  </code></pre>
  
  <p>So when the flag is true, the <code>alert(x[i].text);</code> list correctly the values (--Product--, --Software--, --Services--).</p>
  
  <p>But when I try to get them by their values(index), E.G ..I need to get only (--Services--), so I use <code>x[3].text)</code>, but this returns me the whole List values >>  and not &lt;--Services-->.</p>