Answers for "get parameter"

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
1

query parameters

Query Parameter 
		represented as  key value pair right after the ? 
		https://www.google.com/search?q=iloveyou
	usually used to filter the result
    
    GET /api/spartacus/search?gender=Male&nameContains=li
	if we have more than one query parameter 
		& is used to connect them 
        
 Also there is a Path Parameter|variable
	/api/spartans/{id}  /api/spartans/:id 
	It's used to identify single resource amonth list of resources
	in above example 
		the id is the path parameter to identify single spartan
Posted by: Guest on December-04-2020
0

get javascript parameter

function GetURLParameter(sParam)
{
    var sPageURL = window.location.search.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (var i = 0; i < sURLVariables.length; i++) 
    {
        var sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] == sParam) 
        {
            return sParameterName[1];
        }
    }
}​
Posted by: Guest on September-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language