Let me explain it step by step
- A function of mine is doing a
console.log()on an Knockout observable in a model - Console says
Array(0) - However, at that point I click that
array(0)it displays items. So it is not true there are no items in the array - In between my
Console.log()and the moment I click thearray(0), theobservableArray()has been filled with items, and thus is not empty anymore.
My question here is, is this functionality of the console wrong? Should it actually display the items, or just display an empty array. Why does this happen in the first place?
Or look it at the other way around, should the console update the array(0) with array(50) when there are 50 items in it.
And how do I overcome this issue? Code snippet on working with that:
var myModel = function(){
this.myArray = ko.observableArray();
}
var model = new myModel();
console.log(model.myArray());
model.myArray.push('item');
For this issue, it helped me to add the data to another variable, and log that through console.log().
Example: