DEV Community

Discussion on: JavaScript One-Liners That Make Me Excited

Collapse
 
luckybilly profile image
齐翊 • Edited
q={};location.search.replace(/([^?&=]+)=([^&]+)/g,(_,k,v)=>q[k]=v);q;

got a problem like this:

'?a=&b=1&c='  ----> {b: 1} 

lost key 'a' and 'c'

solution: replace the 2nd '+' by '*'

q={};location.search.replace(/([^?&=]+)=([^&]*)/g,(_,k,v)=>q[k]=v);q;
Collapse
 
healeycodes profile image
Andrew Healey • Edited

Thanks! Fixed it :)