Consider the following ‘push’ scenario.
(global) var refs = [] ;
var record = {id:1, references: ["12","145"]};
refs.push(record);
Nevertheless, when I debug with Chrome, the push function is skipped and the refs array is empty at the end. What is the reason?
EDIT:
The full code is something like this:
gadgets.sciverse.makeRequest(entry['prism:url'], function(obj) {
var testJson = $.xml2json(obj['text']);
// console.log(testJson);
var tempArr = [];
if (!testJson) {
console.log('empty secondary response');
return ;
}
var refSet = testJson ['item']['bibrecord']['tail']['bibliography']['reference'];
if (!refSet)
tempArr = [] ;
else {
$.each(refSet, function(i, e){
tempArr.push(e['ref_info']['refd_itemidlist']['itemid']['text']);
})
}
var verySillyTemp = {
id: pid,
arr: tempArr
} ;
refs.push( verySillyTemp );
},params);
console.log(refs);
Looks like
refsis being set in an asynchronous call and you are logging it before it is set.