Tengo que devolver el valor del tipo de sitio (comercial o personal) de la ruta de la página
La función que uso es:
function currentPath() { var siteType=window.location.pathname; if ( siteType.indexOf('business')) { siteType= 'business'; } else { siteType = 'personal'; } return siteType; }Entonces, si la ruta de la página contiene "negocios", debería devolver negocios y si no contiene "negocios", debería devolver "personal".
function currentPath() { var siteType=window.location.pathname; if ( siteType.indexOf('business') !== -1) { //return -1 if not present siteType= 'business'; } else { siteType = 'personal'; } return siteType; }o
function currentPath() { var siteType=window.location.pathname; if (siteType.includes('business')) { //checks for the string in the given string or array siteType= 'business'; } else { siteType = 'personal'; } return siteType; }Puede usar el método includes() con el operador condicional:
function currentPath() { return window.location.pathname.includes('business') ? 'business' : 'personal'; }