title: check if variable exist in json string
body: <p>I have a problem I can't find out myself so any help appreciated. </p>
  
  <p>I have a dynamic cart which is filled with some JSON data. In the cart the shipping costs are also filled from the same json data. The script itself works when a method is available. When a shipping method isn't available for that country the script should say "not available" or something like that. Instead it returns an undefined error which causes the cart not to work. After some searching I found out that when an user comes from country A (which is supported by the cart) the variable "methods" is present in the Json string. When a user comes from country B (which isn't supported) the variable "methods" is not present in the json string. Obviously that causes the error. 
  So what I try to achieve is to check if the variable "methods" is present or not.
  I found some answers like using typeof, HasOwnProperty, lenght() etc but I can't figure out how I should implement that in the script below.</p>
  
  <p>My script</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
  
          function getPriceDynamicCart(price){
            price = parseFloat(price).toFixed(2);
              price = '€ ' + price.replace('.', ',');
            return price;
          }
          function loadDynamicCart(){
            var url = "{{ '/cart/' | url }}?format=json";
  
            $.getJSON(url,function(data){
  
              var cartHtml = '';
              var priceTotal = 0;
              var foundShipment = false;
  
               $.each(data.cart.products, function(index, product){                  
  
                priceTotal = priceTotal + parseFloat(product.price.price_incl);
                productTitleLimit = jQuery.trim(product.fulltitle).substring(0, 19);
  
                cartHtml = cartHtml +
                  '&lt;div class="cart-product"&gt;&lt;div class="cart-quantity"&gt;' +product.quantity+'&amp;nbsp;x&amp;nbsp;&lt;/div&gt;&lt;div class="cart-title"&gt;&lt;a href="'+ product.url +'" alt="'+ product.fulltitle + '" title="'+ product.fulltitle + '"&gt;' + productTitleLimit + '&lt;/a&gt;&lt;/div&gt;&lt;div class="cart-price"&gt;' + getPriceDynamicCart(product.price.price_incl) + '&lt;/div&gt;&lt;/div&gt;';
              });
  
              $.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;&lt;a class="vracht" style="cursor:pointer;" rel="nofollow"&gt;Verzendkosten:&lt;br /&gt;(Vervallen bij afhalen)&lt;/a&gt;&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(incl. btw): &lt;span&gt;' + getPriceDynamicCart(priceTotal) + '&lt;/span&gt;&lt;/div&gt;';
  
              $('#dynamic_cart').html(cartHtml);
  
            });
          }
  
          $().ready(function(){
            loadDynamicCart();
          });
        &lt;/script&gt;
  </code></pre>