Chrome extension javascript array bug?
Posted
by Wayne Werner
on Stack Overflow
See other posts from Stack Overflow
or by Wayne Werner
Published on 2010-06-13T23:48:33Z
Indexed on
2010/06/13
23:52 UTC
Read the original article
Hit count: 224
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
© Stack Overflow or respective owner