Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE9 array does not support indexOf

Based on http://ie.microsoft.com/testdrive/HTML5/ECMAScript5Array/Default.html, I thought IE9 supports indexOf in array but the following breaks. Any idea why?

<script type="text/javascript">
    var a = [59, 20, 75, 22, 20, 11, 63, 29, 15, 77]; 
    var result = a.indexOf(32);//
    document.write(result);
</script>

Error message as below:

SCRIPT438: Object doesn't support property or method 'indexOf' 

test.php, line 9 character 1

like image 405
tanyehzheng Avatar asked Oct 17 '11 10:10

tanyehzheng


1 Answers

Are you sure your page is running in IE9 mode? Check in dev tools (F12). If you have old DOCTYPE you might be seeing your page in IE8/7 mode, so indexOf is not supported. If you are running in IE9 mode then it works just fine.

like image 126
Aux Avatar answered Sep 23 '22 07:09

Aux