Ian Hickson wrote:
Because developers will be outraged if they get keys sometimes and values other times. Consider:On Wed, 29 Apr 2009, John J Barton wrote:Ian Hickson wrote: window.addEventListener('load', function(event){ sessionStorage["a"] = "letter"; sessionStorage["1"] = "number"; sessionStorage["first"] = "ordinal"; var str = ""; try { for (var i = 0; i < sessionStorage.length; i++) str += "keys["+i+"]="+sessionStorage[i]+"\n"; document.getElementById("result").innerHTML=str; } catch(exc) { document.getElementById("result").innerHTML=exc; } }, true); As I understand your proposal, the correct result would be keys[0]=a keys[1]=number <<< !!! wait it's a value! keys[2]=first I think this is unreasonable and I would expect browser would not agree to implement an API certain to lead to bug reports. BTW FF 3.5 says: keys[0]=undefined keys[1]=number keys[2]=undefined. That is a reasonable answer. This also demonstrates why the length property is not useful: you can't use it in any sensible statements. If you want to iterate the keys, no problem, change the API: var keys = sessionStorage.getKeys(); // array of keys with |length|. jjb |
- Re: Storage 'length' and enumeration Ian Hickson
- Re: Storage 'length' and enumeration timeless
- Re: Storage 'length' and enumeration Sean Hogan
- Re: Storage 'length' and enumeration Sean Hogan
- Re: Storage 'length' and enumeration Boris Zbarsky
- Re: Storage 'length' and enumeration Sean Hogan
- Re: Storage 'length' and enumeration Boris Zbarsky
- Re: Storage 'length' and enumeration Ian Hickson
- Re: Storage 'length' and enumeration John J Barton
- Re: Storage 'length' and enumeration Ian Hickson
- Re: Storage 'length' and enumeration John J. Barton
