Bug with array.length

You must Login before you can answer or comment on any questions.

This is for iPad development

When I define an array var a = {}; a[0] = "hello";

and I print out a.length, I get undefined.

When I define an array var b = new Array(); b[0] = "there";

and print b.length, I get 1.

When I do it the second way, the compiler yells at me for not using the preferred way of defining objects.

In both cases, the arrays hold objects ok, but in the first case, I cannot determine the length of the array.

1 Answer

Accepted Answer

Hi Shawn, I think it's should be

var a = [];
instead of
var a = {}

Your Answer

Think you can help? Login to answer this question!