I am trying to push data to local storage. What I have is basically what others but does not seem to work.
var data = {"fullname":data['name'],"picture":"<img src="+data['picture']+" />"}
var result = JSON.parse(localStorage.getItem("oauth2-test-params"));
result.push(data)
My object looks like this console.log(localStorage)
:
{
"picture": "two",
"fullname": "Junk",
"test-params": "{\"three\":\"77-96L2N\",\"four\":\"junk\",\"five\":\"Bearer\",\"expires_in\":\"3599\"}"
}
What I am looking to do is
{
"test-params": "{
"fullname":"Junk",
"picture": "two",
"three":"77-96L2N",
"four":"junk","five":"Bearer",
"expires_in":"3599"}"
}
I want to add picture and fullname to the test-params object not outside of.
The code I have isn't working and it is what everyone else is using.
I keep getting this error result.push is not a function
Replace
result.push(data)
with
Object.assign(result, data)