You have defined person as an object not as an array. You can probably ise multi-dimensional arrays for that.
vishesh
Nearly a Posting Virtuoso
1,381 posts since Oct 2006
Reputation Points: 85
Solved Threads: 42
Nice work, it didn't got into my mind.
Well Arrays are objects only and collection of well defines similer objects(somewhat like SETS in maths :) ). Its's also stored in a single variable name and you need to know index number of a an elemnet to access that paricular element. On the other hand objects are your own special kind of data, a collection of methods and properties whatever. With objects you could create your own data types. And you of course need to know the variable names to access the data not index number.
Hope this has made the difference clear.
vishesh
vishesh
Nearly a Posting Virtuoso
1,381 posts since Oct 2006
Reputation Points: 85
Solved Threads: 42
the way you're using them, they are synonymous.
arrays store indexed values, but they can also store values by associative keys. Objects can store values by associative keys also; so, when you write person[0] = la, you're creating a key (0) which you can then use to retrieve the Person-class objects from the generic Object named person. You can store values in objects using the more object-orientated "dot" syntax, without ever creating Object classes. Methinks thats bad practice though.
I think that the main difference between objects and arrays is that objects can contain inner functions.
Generally, you should use arrays to store indexed or keyed Objects or values, and you should probably avoid using the generic "Object" entirely. It reduces the strength of the code you're writing: you never really know what "Object" has inside it, or what it does.
EDIT:
I think that the main difference between objects and arrays is that objects can contain inner functions.
...apparently not true:
var test = new Array();
test.test = function(){document.write("werd")};
test["hello"] = 45;
document.write(test["hello"]);
test.test();
does exactly what it says on the tin.
well. you certainly can't prototype, class or extend the Array object.
Come to think of it, you probably can. JavaScript is a bit of a weird one.
MattEvans
Veteran Poster
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64