How to know if a url has parameters in javascript

I want to check if a url has parameters or it doesn't, so I know how to append the following parameters(with ? or &). In Javascript

Thanks in advance

Edit: With this solution it works perfectly:

myURL.indexOf("?") > -1

Solution 1:

Split the string, and if the resulting array is greater than one and the second element isn't an empty string, then at least one parameter has been found.

var arr = url.split('?');
if (arr.length > 1 && arr[1] !== '') {
  console.log('params found');
}

Note this method will also work for the following edge-case:

http://myurl.net/?

You could also match the url against a regex:

if (url.match(/\?./)) {
  console.log(url.split('?'))
}

Solution 2:

You can try this:

if (url.contains('?')) {} else {}