Storing Javascript object in local storage

I was working on a chrome extension where I wanted to store javascript objects in localstorage and retrieve it later. But I was unable to do so with just setting the javascript objects in localstorage. I had to first stringify it and then parse it.

//create a javascript object array.
 var team = [{lead:'Monica',projectManager:'Ross',intern:'Chandler'},

//Store it in the localstorage and name it localStr.

//Retrieve the data and parse it back to JSON.
var retrieveData = JSON.parse(localStorage.getItem('localStr'));

//Write the data to the console.
console.log('and the lead of team 1 is '+ retrieveData[0].lead);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: