I encounter something quite strange while trying to iterate properties of an object stored
using jQuery data function.
Here is the thing (as an example) :
wrapper.data( 'infos', {
label: $('input[name*="label"]').val(),
amount: $('input[name*="amount"]').val(),
etc..
});
Then i try to read values using :
$.each( wrapper.data('infos'), function(k,v) {
console.log(k + ' > ' + v);
});
And i get a beautiful output like :
0 > undefined
1 > undefined
...
239 > undefined
If i output this object as if, i can read properties without any difficulties.
Is it somehow related to jquery caching or something ?
Because your object has a
lengthproperty, it is being interpeted as an array as, in 1.7.2 at least, whether it’s an array or not is determined via:So you should either;
lengthproperty something elseUse a
for / inloop instead.