3

Ok, I have to use the localStorage to store an object, and an array. However, whenever i set something, it stores a string value instead. For example:

var x = [1,2,3];
localStorage["x"] = x;
console.debug(x); //[1, 2, 3]
console.debug(localStorage["x"]); //"1,2,3"

and objects:

var o = {foo:1};
localStorage["o"] = o;
console.debug(localStorage["o"]); //[object Object]
console.debug(o); //Object \ foo: 1 \ __proto__: Object

(\s are line breaks)

How do you store objects and arrays within localStorage.

Also, what is the difference between localStorage, sessionStorage and document.cookie? thanks.

hippietrail
  • 14,735
  • 16
  • 96
  • 147
tcooc
  • 19,794
  • 3
  • 36
  • 55

0 Answers0