Reputation: 67
When I store a 3d array (such as [{name: 'bob',age: '23'},{name: 'anotherperson', age: '54'}]) into a cookie, when I retrieve it, it returns: [object Object]. What does this mean and how can I store it without messing up the array?
Upvotes: 0
Views: 31
Reputation: 314
[object Object]
usually means that you're trying to log an object which hasn't been converted into a string, although it's tough to say what it represents in this current context. It could be the original array you had stored, or it could be something of no use to you. You can probably console.log(JSON.stringify(object))
to find out.
As for storing the array, if you need to store it as a string, you can do
var stringified = JSON.stringify(array);
store(key, stringified);
and then retrieve
storedString = retrieve(key);
var restoredArray = JSON.parse(storedString);
Upvotes: 2