how to fix Object doesn't support property or method 'indexOf'?

Patrioticcow picture Patrioticcow · Oct 23, 2013 · Viewed 9.6k times · Source

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?

Answer

Arun P Johny picture Arun P Johny · Oct 23, 2013

Try using a regex, something like

if(/\/(bob|ginger|grabs)\//.test(image) || /^[^\/]*\/$/.test(image)){
}