Game Development Reference
In-Depth Information
all the different keys are. Thankfully, the sessionStorage.key function allows us
to get a specific key, through which we can then get a hold of the value stored with
that key.
sessionStorage.clear();
sessionStorage.length == 0; // True
sessionStorage.setItem("name", "Rodrigo");
sessionStorage.setItem("book", "Learn HTML5");
sessionStorage.setItem("publisher", "Packt
Pub");
sessionStorage.setItem("isColor", true);
sessionStorage.setItem("rating", 5);
var values = new Array();
for (var i = 0, len = sessionStorage.length; i
< len; i++) {
var key = sessionStorage.key(i);
var value = sessionStorage.getItem(key);
values.push({key: key, value: value});
}
values.length == sessionStorage.length; // True
values[0].key == "book"; // True*
values[0].value == "Learn HTML5"; // True*
Thus, we can query sessionStorage for a key at a given position, and receive the
string key representing that key. Then, with the key we can get a hold of the value
stored with that key. Note, however, that the order in which items are stored within
the sessionStorage object is totally arbitrary. While some browsers may keep the
list of stored items sorted alphabetically by key value, this is clearly specified in the
HTML5 spec as a decision to be left up to browser makers.
Search WWH ::




Custom Search