简体   繁体   中英

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

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.

your code looks right and this compatibility table shows that IE9 should support indexOf() and checks your actual browser for compatibility.

try to open it and take a look at your result. maybe you're running you IE in compatibility mode for IE7/8 or something else.

this jsfiddle works in my IE9 - please try that, too.

It might help if you declare the array explicitly:

var a = new Array(1,2,3);
a.indexOf(2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM