if I write:
var source = new Array();
function doSomething(a){
chrome.bookmarks.search(a,function(items){
for(var i = 0;i<items.length;i++)
{
source[i] = items[i];
}
});
console.log(source[0].title);
alert(source[0].title);
}
in the console I can see the values,but what alerted is “undefined”.
can someone tell me why and how to write to get the values?
You are executing
alertin the wrong scope – you should do this in the callback function. Try this:You have seen the right value in the console because it shows reference to the value which have been already filled in this moment (in the callback function).