Reputation: 8346
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.
Upvotes: 0
Views: 151
Reputation: 96250
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 .
Upvotes: 4
Reputation: 7863
(''+number)[j]
should work in any browser, assuming that number
is something that can be coerced to a String
anyway.
Upvotes: 0