javascript - Associative array to String and String to associative array -


i have convert an associative array string in php. doing as

  $cookievalue = http_build_query(arr,'','sep'); 

and setting cookie using setcookie.

  setcookie('subs',$cookievalue,0,'/'); 

cookie in js side looks like

 "emailid=a1%40a.comsepmaths=0sepphysics=1sepchemistry=2sepbotany=3sepzoology=4se  ptamil=5sepenglish=6seppolity=7sepgk=8sephistory=9" 

i trying convert associative array.

i tried json.parse. it's not useful in case.

i free change both php side , js side functions. aim should easy convert forth , back.

i tried implode on php also.

try this:

var = "emailid=a1%40a.comsepmaths=0sepphysics=1sepchemistry=2sepbotany=3sepzoology=4septamil=5sepenglish=6seppolity=7sepgk=8sephistory=9";   var myarr = {}; var sep = "sep";  a.split(sep).foreach(function(item){      var sepp = item.indexof("=");      myarr[item.substr(0,sepp)] = decodeuricomponent(item.substr(sepp+1));  }); console.log(myarr); 

here's demo.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -