Reputation: 143
Please checkout this JS Bin http://jsbin.com/iqikuf/3/edit
When the below is run in the console, the result shown makes sense to me.
statement: vd.tools.push(dataItem);
resuelt: 2
But why do we get the below result when run in the console?
statement: vd.tools.length
result: 0
Upvotes: 2
Views: 158
Reputation: 1238
I would like to integrate and explain DCoder's answer.
vd.tools
refer to an observableArray which is a Javascript object which length
property does not refer to the amount of stored items.
By "adding the parenthesis" vd.tools()
we get a reference to the underlying array which is wrapped by the KnockoutJS's observableArray.
This is the real array which store our data and here we can ask for the length
property expecting the correct result.
So then DCoder's answer make perfect sense.
Upvotes: 1