Opened 14 years ago
Closed 14 years ago
#4319 closed bug (invalid)
$.each can't work with Associative array
Reported by: | chuiwenchiu | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.3.2 |
Component: | core | Version: | 1.3.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
My Test Enviroment: IE7 jQuery Version: 1.3.1 & 1.3.2
Description: if i use "Associative array" in each(), the method not work is it bug ? Test Code: var a = [ 'a' ]; a[a.length] = 'b'; a[2] = 'c'; a[ '3' ] = 'd';
a[ 'four' ] = 'e';
fail: skip a[ 'four' ]
$.each(a, function(i, val) {
alert('Test#5 >> ' + i + ':' + val);
});
var b = []; b[ 'one' ] = 1; b[ 'two' ] = 2;
$.each(b, function(i, val) {
fail: no run here
alert('Test#6 >> ' + i + ':' + val);
});
Attachments (1)
Change History (3)
Changed 14 years ago by
Attachment: | test_jquery132.html added |
---|
comment:1 Changed 14 years ago by
comment:2 Changed 14 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
Per the documentation, if the object you pass in has a length property, the object will be treated as an array and iterated from 0 to length-1.
http://docs.jquery.com/Utilities/jQuery.each#objectcallback
each() use 'length' property detect Array or Object,
if ( length === undefined ) {
} else
---
BUT ASSOCIATIVE ARRAY has 'length' property, but not use object[i] get eleemnt of array, need to use
...