I am pushing a vector into array in the loop. Here is a code snippet
var atoms = [];
for (var i=0; i<formulas.length; i++) {
for (var atom in formulas[i].data.atoms) {
if (atoms.indexOf(atom) < 0) {
atoms.push(atom);
}
}
}
var zeroMatrix = [];
for (var i=0; i<formulas.length; i++) {
var vector = atoms.map(function(item) {return formulas[i].data.atoms.hasOwnProperty(item) ? formulas[i].data.atoms[item] : 0});
vector.push(0);
console.log(vector);
console.log(zeroMatrix);
zeroMatrix.push(vector);
console.log(zeroMatrix);
}
Results printed into the console are as follows
1) [1,2,0,0] // vector
2) [] // zeroMatrix
and now surprise
3) [[1,2,1,0],[2,0,1,0],[0,1,1,0]] // zeroMatrix after pushing the vector
Moreover, it pushes as expected if I run this in debug. Do you have any idea what can cause this behavior?