Search code examples
javascriptjqueryinternet-explorer-8indexoflastindexof

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


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?


Solution

  • Try using a regex, something like

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