title: JavaScript - Uncaught TypeError: Cannot read property 'search' of undefined
body: <p>When I execute my Javascript I'm getting this error:</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'search' of undefined </p>
  </blockquote>
  
  <p>And I don't know how do fix it and why that is shown.</p>
  
  <p>I have objects inside an  array,</p>
  
  <p>example:</p>
  
  <pre><code>AsukohaArray = [{"Punkt":[[58.1056],[23.2589]],
                      "name":"Haapsalu Raamat",
                      "PunktiID": 23}];
  </code></pre>
  
  <p>My code </p>
  
  <pre><code>$(document).ready(function() {
    $("input[type='search']").keyup(function() {
      var searchTerm = $(this).val();
      var myExp = new RegExp(searchTerm, "i");
      var output = "&lt;ul id='result'&gt;";
      $.each(AsukohaArray, function(key, val) {
        //console.log(val.name);
        if ((val.name).search(myExp) != -1) {
          output += '&lt;li&gt;';
          output += val.name;
          output += '&lt;/li&gt;';
        }
      });
      console.log(output);
      output += "&lt;/ul&gt;";
      $('div#update').html(output);
    });
  });
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;ons-page id="my-page"&gt;
      &lt;ons-toolbar&gt;
          &lt;div class="left"&gt;
              &lt;ons-toolbar-button ng-click="menu.toggleMenu()"&gt;&lt;ons-icon icon="ion-navicon" style="font-size: 32px; width: 1em;"&gt;&lt;/ons-icon&gt;&lt;/ons-toolbar-button&gt;
          &lt;/div&gt;
  
          &lt;div class="center"&gt;Kaardi vaade&lt;/div&gt;
      &lt;/ons-toolbar&gt;
      &lt;div id="nupuriba"&gt;
      &lt;input type="search" class="search-input" id="#search"&gt;
      &lt;/div&gt;
      &lt;div id="update"&gt;&lt;/div&gt;
      &lt;div id="map-canvas"&gt;
      &lt;/div&gt;
  &lt;/ons-page&gt;
  </code></pre>
  
  <p>When I insert "Haapsalu" then results are:</p>
  
  <p>Haapsalu piiskopilinnus
  Haapsalu Kunstikool
  Haapsalu Raamat
  Uncaught TypeError: Cannot read property 'search' of undefined</p>
  
  <p>I have searched that error, but no result, haven't found nothing similar.</p>