title: update and remove json data from a cookie containing shopping cart items
body: <p>I am storing the shopping cart items (json data) in cookie via jquery. 
  I am able to add items to the cookie. Following is the javascript code.</p>
  
  <pre><code>$.cookie.json = true;
  // empty cart
  var emptydata = { "cartItems": [] };
  
  var devicedata = new function (deviceId, qty) {
  return { "deviceId": deviceId, "quantity": qty };
  }
  
  
  // to create json data
  function createJSON(id, qty) {
      if (!$.cookie('devicelist')) {
        $.cookie('devicelist', emptydata);
      }
   devicedata.deviceId = id;
   devicedata.quantity = qty;
   cart = $.cookie('devicelist');
   cart.cartItems.push(devicedata);
   return cart;
  }
  
  // function to be called , when Add to cart button is clicked
  function saveItems() {
  
     var deviceId = $('#lbldeviceId').html();
     var Qty = $('#txtQty').val();
  
     var jsondata = createJSON(deviceId, Qty);
  
     $.cookie('devicelist', jsondata);
  
  }
  </code></pre>
  
  <p>sample json data </p>
  
  <pre><code> { "cartItems": [
     {
       "deviceId": "1",
       "quantity": "1"
     },
     {
       "deviceId": "2",
       "quantity": "1"
     }
  ]}
  </code></pre>
  
  <p>How can i update the quantity of an existing device and remove an existing device in the cookie?
  Hope it can be done by looping through the items. If any other alternatives are there, please suggest me. Also is my approach good or should i go for some other approach?</p>