I have a Javascript object defined as follows:
var active = {
waypoints: [],
scenario: []
}
I am running an array script with:
var myScenario = {
id: terrainId,
text: text
};
active.scenario.push(myScenario);
However, I get 0 when:
console.log(active.scenario.length);
So of course, I cannot iterate over the contents of the array. If I do this:
console.log(active.scenario)
I see the contents of the array in Chrome plus the correct length of the array. I have a similar code that defines and works with arrays, but outside the definition of an object.
Very grateful for understanding why the length is 0.
source
share