DEV Community

Discussion on: JavaScript One-Liners That Make Me Excited

 
luckybilly profile image
齐翊

Hey, that one could not accept empty value (eg:'?a=&b=1&c=')
try this instead:

//keys should not be empty, but value can
q={};location.search.replace(/([^?&=]+)=([^&]*)/g,(_,k,v)=>q[k]=v);q;