Link to home
Start Free TrialLog in
Avatar of skij
skijFlag for Canada

asked on

JavaScript: Storing and retrieving objects with localStorage

Using JavaScript local storage, how can store an object and then retrieve data from that that object?  

Here is an example of my object:
localStorage.setItem('data', {color:'red', number:5});

When I try to retrieve that data I get [object Object]
alert( localStorage.getItem('data') );

How can I get the value of data.color from that object?
Avatar of zzynx
zzynx
Flag of Belgium image

Does this work?
alert( localStorage.getItem('data').color );

Open in new window

SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial