Skip to main content

Bug Tracker

Side navigation

#6919 closed enhancement (wontfix)

Opened August 19, 2010 06:15PM UTC

Closed November 22, 2010 04:58AM UTC

$.each looping over a string produces different results in IE8 Compatibility Mode

Reported by: bkorte Owned by:
Priority: low Milestone:
Component: traversing Version: 1.4.2
Keywords: each ie7 Cc: dmethvin
Blocked by: Blocking:

It's simplest to explain in code:



Safari 5.0.1 on OSX 10.6.4:

0 "s"

1 "t"

2 "r"

3 "i"

4 "n"

5 "g"

IE8 on Windows 7 running in Compatibility Mode (as well as IE7 mode chosen direct from the developer tools inspector):

LOG: 0undefined

LOG: 1undefined

LOG: 2undefined

LOG: 3undefined

LOG: 4undefined

LOG: 5undefined

Simple workaround is:

c = (c === undefined) ? val.charAt(i) : c;

Expected result would be what Safari does.

Attachments (0)
Change History (7)

Changed August 19, 2010 06:18PM UTC by bkorte comment:1

Forgot to mention this is running with 1.4.2.

Changed August 21, 2010 12:28AM UTC by dmethvin comment:2

resolution: → invalid
status: newclosed
type: bugenhancement

The docs for jQuery.each say you should pass in a Javascript Object or Array, so a primitive string isn't a documented or supported argument there. Numbers, Booleans, Dates, null, and undefined are also not supported.

I'll recast this as an enhancement request but would vote against it because there are better ways to deal with strings and $.each is so widely used.

Changed August 21, 2010 12:28AM UTC by dmethvin comment:3

resolution: invalid
status: closedreopened

Changed October 24, 2010 04:44PM UTC by rwaldron comment:4

cc: → dmethvin
priority: → undecided

Dave, can we clarify why this was reopened? If $.each is supposed to be "kind of" like forEach, then strings aren't supported. Additionally, like you even pointed out - nowhere in the docs does jQuery support strings.

Also, it missed the 1.4.3 milestone due date.

Changed October 24, 2010 04:50PM UTC by rwaldron comment:5

priority: undecidedlow

Changed November 12, 2010 02:40AM UTC by snover comment:6

milestone: 1.4.3

Resetting milestone to future.

Changed November 22, 2010 04:58AM UTC by snover comment:7

resolution: → wontfix
status: reopenedclosed

If you want to iterate a string, use $.each(str.split(''), fn).