title: Startswith function for searching an array
body: <p>I have a function that is giving me some trouble.  The code below returns the error message "Cannot read property 'value' of undefined".  The function should just search through the values in the accountlist and return the one that starts with the submitted string.  In the example, submitting "000555" should return 0.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var accountlist = [{
      "value": "000555 - TEST ACCOUNT NAME1",
      "data": "184"
  }, {
      "value": "006666 - TEST ACCOUNT NAME2",
      "data": "450"
  }, {
      "value": "007777 - TEST ACCOUNT NAME2",
      "data": "451"
  }];
  
  function startswith(inputlist, searchkey, inputstring) {
      var searchlength = inputstring.length;
      console.log("starting search");
  
      for (var il = 0; il &lt; inputlist.length; il++) {
          if (inputlist[il].window[searchkey].substring(0, (searchlength - 1)) == inputstring) {
              console.log("FOUND IT " + il + "      " + inputstring);
              return il
          }
      }
  }
  
  startswith(accountlist, "value","000555");</code></pre>
  </div>
  </div>
  </p>