title: Cannot read property 'indexOf' of undefined
body: <p>i'm trying to set different options for several datepickers in jquery.
  My code is looks like this:</p>
  
  <pre><code>{foreach $cart-&gt;getItems() as $item}
      {if $item-&gt;action-&gt;prereservation}
          var disableDates = new Array();
          {if $item-&gt;action-&gt;hasVariants()}
          disableDates[{!$item-&gt;id}] = {$disabledDates[$item-&gt;action-&gt;id][$item-&gt;idVariant]};
          {else}
          disableDates[{!$item-&gt;id}] = {$disabledDates[$item-&gt;action-&gt;id]};
          {/if}
  
          if (disableDates[{!$item-&gt;id}].length !== 0) {
              $(".datepicker_"+'{$item-&gt;id}').datepicker({
                  maxDate: new Date('{!$item-&gt;action-&gt;voucherTo|date: Y-m-d}'),
                  beforeShowDay: function(date){
                      var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
                      console.log(disableDates[{!$item-&gt;id}]) // result is undefined (but not for last iteration)
                      return [ disableDates[{!$item-&gt;id}].indexOf(string) == -1 ]
                  }
              })
          } else {
              $(".datepicker_"+'{$item-&gt;id}').datepicker({
                  maxDate: new Date('{!$item-&gt;action-&gt;voucherTo|date: Y-m-d}'),
              })
          }
      {/if}
  {/foreach}
  </code></pre>
  
  <p>but if there is more than one item in foreach, my js console show error Cannot read property 'indexOf' of undefined for the first iteration, only last is good. Can anybody help me please?</p>
  
  <p>In my code Im combining template system Latte and jquery.</p>
  
  <p>This is my final code in browser:</p>
  
  <pre><code>var disableDates = new Array();
          disableDates[777955] = ["2014-07-25","2014-07-26","2014-07-27","2014-07-28","2014-07-29","2014-07-30","2014-07-31"];
  
          if (disableDates[777955].length !== 0) {
              $(".datepicker_"+'777955').datepicker({
                  maxDate: new Date('2014-07-31'),
                  beforeShowDay: function(date){
                      var string = jQuery.datepicker.formatDate('yy-mm-dd', date);
                      return [ disableDates[777955].indexOf(string) == -1 ]
                  }
              })
          } else {
              $(".datepicker_"+'777955').datepicker({
                  maxDate: new Date('2014-07-31'),
              })
          }
  </code></pre>
  
  <p>Thanks for any advices</p>