Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Page path value - JS variable

I have to return site type (business or personal) value from page path

The function I use is:

    function currentPath() {
      var siteType=window.location.pathname;
      if ( siteType.indexOf('business')) {
        siteType= 'business';
      } else {
        siteType = 'personal';
      }
      return siteType;
    }

So if page path contains "business", it should return business and if it does not contain "business" it should return "personal".

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Use includes()

function currentPath() {
  var siteType = window.location.pathname;
  if (siteType.includes('business')) {
    return 'business';
  } else {
    return 'personal';
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

indexOf

function currentPath() {
  var siteType=window.location.pathname;
  if ( siteType.indexOf('business') !== -1) { //return -1 if not present
    siteType= 'business';
  } else {
    siteType = 'personal';
  }
  return siteType;
}

or

includes

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;
}
about 4 years ago · Juan Pablo Isaza Report

0

You can use includes() method with conditional operator:

function currentPath() {
  return window.location.pathname.includes('business') ? 'business' : 'personal';
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!