Kenneth said:
I know that "length" is a standard property of arrays ...
But, can the programmer create their own *new* array properties?
Yes, as long as they do not collide with the built-in ones.
Something like this:
var a = new Array();
a[0].foo = 3;
a[1].foo = 7;
... ... ...
But here you would be creating the `foo' property on elements of the array
encapsulated by the Array object referred to by `a'. That is not what is
usually understood as "array property", but e.g.
a.foo = 3;
would (cf. a.length).
I can't seem to get it to work ...
The above cannot work because you can only create properties on objects.
a[0] and a[1] do not refer to objects, the property access must result in
`undefined' (the array has been initialized with no elements, its length
property value is 0.) If you had initialized the array with
var a = new Array({}, {});
or
var a = [{}, {}];
(or other values that can be converted to a object that can be augmented
with properties each), it would have worked because each {} creates a new
Object instance (with only inherited properties) and results in a reference
to that object.
Your error description could and should have been a bit more verbose, see
also said:
Seriously, I read "Prof Kenneth J Hacker" the first time¹
HTH
PointedEars
___________
¹ probably inspired by ESR's "J Random Hacker"