Chrome extension javascript array bug?
- by Wayne Werner
Hi,
I'm working on a Google Chrome extension. In the popup I have the following code:
var bookmarks = [];
function appendBMTnode(node){
bookmarks.push([node[0].title, node[0].id]);
}
function addchildren(results){
for(x = 0; x < results.length; x++){
bookmarks.push([results[x].title, results[x].id]);
chrome.bookmarks.getChildren(results[x].id, addchildren);
}
}
function getallbookmarks(){
chrome.bookmarks.get('0', appendBMTnode);
chrome.bookmarks.getChildren('0', addchildren);
}
console.debug(bookmarks.length);
console.debug(bookmarks);
Now, I would assume that the first command would issue the # of bookmarks I have. Indeed, when I use Chrome's debugger and add bookmarks.length to the watch list, 418 is the value. In the console of the debugger I can write bookmarks.length and it will give me the correct length. I can type
for(x = 0; x < bookmarks.length; x++){ console.debug(bookmarks[x]); }
and I get string representations of each inner array. However, that original console.debug(bookmarks.length) gives an output of zero. And if I add console.debug(bookmarks[0]); to the popup.html it tells me that the value is undefined.
This seems like a bug to me, but my real question is how can I iterate over this list?
Thanks