Bug Tracker

Opened 14 years ago

Closed 14 years ago

Last modified 11 years ago

#4180 closed bug (invalid)

jQuery.each() bug on Internet Explorer when used on strings

Reported by: gaby Owned by:
Priority: major Milestone: 1.3.2
Component: core Version: 1.3.1
Keywords: each string Cc:
Blocked by: Blocking:


Hi, if you use the jQuery.each() on a string, it will not yield the same results on IE and the rest of the browsers..


var str= 'abc';
jQuery.each(str, function(index, item)
        $('#display').append('<br />' + idx + ' : ' + item);

after this the #display will have on all browsers but IE


on IE it will be


some thing happens if the callback is without parameters and we use 'this'

var str= 'abc'; 
jQuery.each(str, function() 
 $('#display').append('<br />' + item); 

all browsers will display the letters one-by-one, but IE will display undefined for each letter (so the loop is working but it messes up the data)

Shouldn't it work, since a string is an array ?


Change History (1)

comment:1 Changed 14 years ago by dmethvin

Resolution: invalid
Status: newclosed

The string[index] syntax for obtaining a character isn't standard Javascript. If you want to get a character in a standard way you should use string.charAt(index).

If you want to use $.each on a string, you could split it into an one-char-per-element array beforehand with string.split("").

Note: See TracTickets for help on using tickets.