0

I am making a shopping cart via javascript/jQuery and I am using localStorage. However, I am running into a problem setting the key value of an object. I created this function, but it has not been successful:

function update_aantal(e){
  var value = $(e).parent().find(".form-aantal-val");
  var size = $(e).closest('td').attr('class');
  console.log(size);
  valuepush = {
       size: value.val()
   };
   var cart = JSON.parse(localStorage.getItem("src"));
   $.extend(cart[0], valuepuch );
   localStorage.setItem("src",JSON.stringify(cart));
}

The console.log(size) shows the correct value that I want to change/add into the localStorage but the size in the object valuepush says "size" when the function is complete and the value is added.

How can I pass the size as an object so that the value of size is stored?

Josh Mein
  • 28,107
  • 15
  • 76
  • 87
Tim567
  • 775
  • 1
  • 5
  • 22

1 Answers1

1
var valuepush = {};
valuepush[size] = value.val();
Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55