javascript - How can I store key in jQuery -


here code :

function addtocart(id,price) {     var qty = $("#txt_qty" + id).val();     var qty1 = new array(); if (qty == '' || qty == 0) {     alert('please enter quantity');     $("#txt_qty" + id).focus();     return false; } if (qty != '' && type != '') {     proid.push(id);     var text = 'qty'+id+'='+qty;     var keyvaluepair = text.replace(/ /g,'').split('=');     qty1.push([keyvaluepair[0]] = [keyvaluepair[1]]); }          

i need store key in qty1 array,i have value called qty

how can dynamically store key in qty1 array

i trying above attempt not succeeded

can me

if got data value keyvaluepair[0] , keyvaluepair[1], try use :

var myobj = {}; // declare obj container myobj[keyvaluepair[0]] = keyvaluepair[1]; // set key , value based on variable qty1.push(obj); // push obj qty1(array) variable 

this alternative, can try use solution provided @disha v.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -