Answers for "javascript read parameter from get"

2

javascript get parameter

let params = {};
window.location.search.slice(1).split('&').forEach(elm => {
  if (elm === '') return;
  let spl = elm.split('=');
  const d = decodeURIComponent;
  params[d(spl[0])] = (spl.length >= 2 ? d(spl[1]) : true);
});

// https://example.com/?foo=bar&best%20food=D%C3%B6ner
params['foo'] // bar
params['best food'] // Döner
Posted by: Guest on June-11-2020

Code answers related to "javascript read parameter from get"

Code answers related to "Javascript"

Browse Popular Code Answers by Language