I have a long array of strings with page IDs; when the current page ID matches one from the array, stuff needs to happen (alert in this test).
The alert pops up on any pages, regardless if the url contains one of the ids from the array or not. What is wrong with my if statement: if(pageHref.indexOf(id))
? thanks for any advise
var pageHref = window.location.href;
var ids = ['14528','14417','17529'];
for (var i = 0; i < ids.length; i++) {
var id = ids[i];
if (id.length > 0) {
if(pageHref.indexOf(id)){
//do something
alert('a');
}
}
}