Javascript Array not working in IE7 and older versions but working in IE10 Here is my code which is working in IE10 but not working in IE7.
number = "123";
var j=0;
alert(number[j]);
Result in IE7
undefined
Result in IE10
1
Please let me know how to call the variable values as single dimension array in older browsers.
Javascript Array not working in IE7
This is not an array “not working” – you have a string value here (the browser will convert it to one, because for numbers no such kind of access is defined), and are trying to access it's single characters with a zero-based index.
Older IE simply don't support this – so cast it to a string (implicitly/explicitly) and then use the charAt
method of the String object instead .
(''+number)[j]
应该可以在任何浏览器中使用,前提是该number
仍然可以强制转换为String
。
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.