Reputation: 27038
i have this situation:
if (image.indexOf("/bob/") != -1 || image.indexOf("/grabs/") != -1 || image.indexOf("/") == image.lastIndexOf("/")) {
alert('success');
}
in IE8 i get Object doesn't support property or method 'indexOf'
i could probably use something like $.inArray("/bob/", image)
, but im not sure about lastIndexOf
any ideas how can i solve this?
Upvotes: 1
Views: 9712
Reputation: 816334
If you want to solve it with jQuery, you could do
$.inArray("/", image, $.inArray("/", image)) === -1
i.e. look for the next occurrence of /
after the first occurrence. This assumes that /
is always present in the array. If not, then the equivalent would be
var index = $.inArray("/", image);
if (.... || (index === -1 || $.inArray("/", image, index) === -1)) {
// ...
}
Upvotes: 0
Reputation: 388316
Try using a regex, something like
if(/\/(bob|ginger|grabs)\//.test(image) || /^[^\/]*\/$/.test(image)){
}
Upvotes: 1