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: |
Description
It's simplest to explain in code:
Given:
$.each('string',function(i,c){console.log(i,c);});
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 comment:1
Changed August 21, 2010 12:28AM UTC by comment:2
resolution: | → invalid |
---|---|
status: | new → closed |
type: | bug → enhancement |
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 comment:3
resolution: | invalid |
---|---|
status: | closed → reopened |
Changed October 24, 2010 04:44PM UTC by 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 comment:5
priority: | undecided → low |
---|
Changed November 12, 2010 02:40AM UTC by comment:6
milestone: | 1.4.3 |
---|
Resetting milestone to future.
Changed November 22, 2010 04:58AM UTC by comment:7
resolution: | → wontfix |
---|---|
status: | reopened → closed |
If you want to iterate a string, use $.each(str.split(''), fn)
.
Forgot to mention this is running with 1.4.2.