Javascript variable = x or y possible?

I am using the following javascript to get URL parameters ...

function getUrlParams() {
  var params = {};
  window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) {
    params[key] = value;
  });
  return params;
}
var params = getUrlParams();
var urlvars = (params.email);

URL has ?email=email@domain.com&fbemail=email@domain.com

In most cases, one of these values ​​is empty, otherwise they are the same. Therefore i try to dourlvars = (params.email) or (params.fbemail)

What is the best way to do this?

+3
source share
2 answers

I will continue and make my comment the answer. Why not literally write what you said?

urlvars = params.email || params.fbemail;
+7
source
var urlvars = (params.email == "" ? params.fbemail : params.email);
+2
source

All Articles