If my browser is on http://example/cars?type=ford, searchParams.get(type)
returns null
, and if it on http://example/cars?type=ford&type=dodge, it returns dodge
. How can the first parameter after the question mark be included. I am operating Chrome Version 64.0.3282.167 (Official Build) (64-bit).
my.filter=function(type,value){
var searchParams = new URLSearchParams(window.location.href);
var search=searchParams.get(type);
console.log(search)
if(search) {
search=search.split(',');
if(!search.indexOf(value)) {
search.push(value);
searchParams.set(type,search.join(','));
}
}
else searchParams.append(type,value);
var url=searchParams.toString();
console.log(url);
//window.location.href = url;
}