You can use String.prototype.indexOf
to determine if one string contains another one, but it will return true
if place
substring takes place in any part of the URL.
Another approach is to use JavaScript URL object:
var urlObject = new URL("http://www.abctest.com/?user=someVal&place=someVal");
var query = urlObject.search.substring(1); // user=someVal&place=someVal
var hasPlaceParameter = query.split('&').some(function(x) {
return x.substring(0, 6) === 'place=";
});
You can use ES6 startsWith
function instead of substring(0, 6)
.
2
solved Check query string is present [closed]