Bug Tracker

Ticket #4180 (closed bug: invalid)

Opened 6 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

Description

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..

example.

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

0:a
1:b
2:c

on IE it will be

0:undefined
1:undefined
2:undefined

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 ?

regards

Change History

comment:1 Changed 6 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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.