javascript - Why does the console print an object in an array but not an object -
this question has reply here:
storing objects in html5 localstorage 19 answersi have following:
var allitems = {items: [ {value: 1, name: "string1"}, {value: 2, name: "string2"}, {value: 3, name: "string3"} ] }; localstorage.setitem('allitems', allitems);
i'm struggling access properties of allitems
after retrieving localstorage. how access name of sec object in array items?
you have utilize json stringify
store object , utilize parse
convert json object.
localstorage.setitem('allitems', json.stringify(allitems)); var storageitems = json.parse(localstorage.getitem('allitems')); console.log(storageitems.items[1].name);
javascript
No comments:
Post a Comment