Jquery build in a check to see if available
<p>I have a question that I can't figure out myself. 
I the below piece of code I want to build a check to see if a shipping method is available. This is important because when somebody use my website and there isn't a shipping method available for that country he/she gets an "undefined error".</p>

<p>My code:</p>

<pre><code>    $.each(data.cart.shipping.methods, function(index, method){


        if(!foundShipment &amp;&amp; !method.cod &amp;&amp; !method.pickup){

        priceTotal = priceTotal + parseFloat(method.price.price_incl);

        cartHtml = cartHtml +
          '&lt;div class="cart-shipping"&gt;{{ 'Verzendkosten:' | t }}&lt;br /&gt;(€500 franco)&lt;div class="cart-price"&gt; ' + getPriceDynamicCart(method.price.price_incl) + '&lt;/div&gt;&lt;/div&gt;';

        foundShipment = true;
      }
    });
    cartHtml = cartHtml +
      '&lt;div class="cart-total"&gt;&lt;div class="total"&gt;Totaal (excl. btw): &lt;span&gt;' + getPriceDynamicCart(priceTotal) + '&lt;/span&gt;&lt;/div&gt;';

    $('#dynamic_cart').html(cartHtml);

  });
</code></pre>

<p>I thought, after reading this website, it would be usefull to use .lenght:</p>

<pre><code> if($(data.cart.shipping.methods).lenght){ 

 if(!foundShipment &amp;&amp; !method.cod &amp;&amp; !method.pickup){

            priceTotal = priceTotal + parseFloat(method.price.price_incl);

            cartHtml = cartHtml +
              '&lt;div class="cart-shipping"&gt;{{ 'Verzendkosten:' | t }}&lt;br /&gt;(€500 franco)&lt;div class="cart-price"&gt; ' + getPriceDynamicCart(method.price.price_incl) + '&lt;/div&gt;&lt;/div&gt;';

            foundShipment = true;
          }
        });
        cartHtml = cartHtml +
          '&lt;div class="cart-total"&gt;&lt;div class="total"&gt;Totaal (excl. btw): &lt;span&gt;' + getPriceDynamicCart(priceTotal) + '&lt;/span&gt;&lt;/div&gt;';

        $('#dynamic_cart').html(cartHtml);

      });
}
else {
              cartHtml = cartHtml +
              '&lt;div class="cart-total"&gt;&lt;div class="total"&gt;Not Available&lt;/div&gt;';
}
</code></pre>

<p>Obvious that doesn't work. I'm pretty new to jquery so if anyone can help me with this that would be awesome. </p>
