DEV Community

Discussion on: JavaScript One-Liners That Make Me Excited

Collapse
 
healeycodes profile image
Andrew Healey

This is brilliant, Ben! 😄

Collapse
 
lexlohr profile image
Alex Lohr

I can probably do it in even less characters... let me try:

q={};document.location.search.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v);q;
Thread Thread
 
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;