I have the following conditional statement in JS:
if(url === 'http://www.productionlocations.com/locations' || url === 'http://www.productionlocations.com/locations/')
I'm trying to make it more efficient so I tried this:
function stripTrailingSlash(str) {
if(str.substr(-1) == '/') {
return str.substr(0, str.length - 1);
}
return str;
}
theurl = stripTrailingSlash(url);
if(theurl === 'http://www.productionlocations.com/locations')
But obviously that just makes it into more code :)
What's the most efficient way of doing this? I had tried using indexOf() before, but it didn't work. Thanks for your help!
str.replace(/\\$/, '')