<jh*****@yahoo. com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
I don't know where the actual issue is,
but hopefully someone can explain.
The following displays "5" in FireFox, but "3" in IE:
<script type="text/javascript" language="javas cript">
var newString = ",a,b,c,";
var treeArray = newString.split (/\,/i);
alert(treeArray .length);
</script>
Thanks,
Jim
You've found one of the known issues with the String#split() method and
IE.
When you call split() using a String as the argument, IE includes empty
items in the resulting Array.
When you call split() using a RegExp as the argument, IE drops empty
items in the resulting Array.
var s = 'a#b##c###d';
// "4" - all Array elements contain non-empty strings
alert(s.split(/#/).length);
// "7" - Array elements 2, 4 and 5 are empty strings
alert(s.split(" #").length);
Note that in Gecko-based browsers and Opera, both alert "7". So the
simplest solution is probably to use String#split() with a String as the
parameter instead of a RegExp.
--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ -
http://jibbering.com/faq