views:

27

answers:

1

I am trying to browse a string using javascript. Here I am only displaying the value of each characters in the string:

var value ="123#sometest";
for(var i=0; i< value.length;i++){
  alert(value[i]);
}

This works fine in Firefox, but in IE (6 and 7), this breaks. value exists, i exists, but value[i] is undefined.

Any idea why and how to fix this?

Thanks

+4  A: 

Use the charAt() function:

var value ="123#sometest";

for (var i = 0; i < value.length; i++) 
{
  alert(value.charAt(i));
}
Tim S. Van Haren
thanks it worked! this is annoying that IE doesn't support [] :\
marcgg
ie does many annoying things ;)
Jason