I have an object containing an array of objects. I am able to save this data into the chrome.storage. Also able to get the data back as an object. But am totally stuck on how to read from this..
Say, I have the following data:
var x = {'data': [{name: '', id: '', url: '',
'dataquery': [{name: '', url: '', lookfor: '', getback: ''}] }] };
Now say, I save this into chrome storage (using set), and later get this data back as an object 'd' (using get), how do I access, say the id or url of the first array? Shouldn't it be like this:
d.data[0].url // ??
But this gives an error. What am I doing wrong? what is the proper syntax?
EDIT, with more details: Here is the code am using to set and get the data:
// SETTING THE DATA
chrome.storage.sync.set(x, function() {
console.log('STORED'); });
// GETTING THE DATA
var d;
chrome.storage.sync.get('data', function(data) {
d = data;
console.log(d);
});
alert(d.data[0].loginurl);
I can see from my console logs that the data has been stored and retrieved properly. I can see the data (as an object) in console.log (shows the array and all elements when you expand).
But the alert line, gives the following error: 'Uncaught TypeError: cannot read property 'data' of undefined'