Is there a more efficient way of searching the window.location.href?
window.location.href: http://www.example.com/6CATA/folder/file.html
The current code I have is:
var searchWinHref = window.location.href;
if(searchWinHref.indexOf("/6CATA/") > -1) {
alert('6CATA is in the window.location.href');
}
Which works just fine, but I’m trying to learn ways to optimise code where possible and if I need to do this a couple of times on a page, I’m curious to know if there’s a more efficient way to do it?
EDIT:
To clarify, I need to occasionally search the URL for different variations, e.g: 6CATA & 6CATB etc.
http://jsperf.com/test-vs-match-vs-indexof-vs-search-2/2
Here is a benchmark, no need for optimization in this case