Opened 12 years ago
Closed 12 years ago
#6919 closed enhancement (wontfix)
$.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.
Change History (7)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
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.
comment:3 Changed 12 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
comment:4 Changed 12 years ago by
Cc: | dmethvin added |
---|---|
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.
comment:5 Changed 12 years ago by
Priority: | undecided → low |
---|
comment:7 Changed 12 years ago by
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.