So I am facing this issue which to me seems quite weird. Can't seem to understand what's going on here. I create a new Array. Pass it to as a parameter to a function which populates it. Then log the array on the console. It displayes the values properly. But on the very next line, if I log the length of the array , It gives me a 0
} else {
var path = new Array();
fetchPath(arr[index].parentId,path);
console.log(path);
console.log(path.length);
}
This is fetchPath
function fetchPath( id, path ) {
chrome.bookmarks.getSubTree(id, function(subtree) {
path.push(subtree[0].title);
if(subtree[0].hasOwnProperty('parentId')) {
fetchPath(subtree[0].parentId,path);
}
});
This is what I get on the console
Array[4]
0:"India"
1:"News"
2:"Bookmarks Bar"
3:""
length:4
>_proto_:Array[0]
0
Why is the length reported to be zero ? Infact no matter what I try and do with the array it fails because I've leterally lost it. I've put the entire JS file here http://jsfiddle.net/1u4zngko/