View Full Version : Newbie question about using arrays as objects

07-04-2011, 12:03 AM

i know a little php, but new to javascript. much of the syntax is identical.

i'm reading the new rhino book (flanagan 6th).

in it, where he introduces METHODS, he says "When we combine FUNCTIONS with OBJECTS we get METHODS". Then he creates an empty ARRAY:

var a = [];

then he uses the "push() method" to add elements to the array.


uh, methods are for *objects* right? Yet he is using them on an ARRAY.

Can somebody help me see the light on how an array can magically becomes an object that is manipulated by a "method"?

I mean, the array is still an array, no? It never actually becomes an object, right? Yet we still use a *method* to manipulate it. See my conceptual quandry?

07-04-2011, 07:46 AM
It does not magically become an object, it is an object

See for yourself

var a = [];
alert(typeof a);

You will get "object"