On 02/08/2006 21:36, Andy Dietler wrote:
If I an objects called: MetaData1, MetaData2, MetaData3, etc. and I
want to use a loop to get the value of say each object's length how can
I do that?
Perhaps the simplest approach to have an array of MetaData. If that's
not possible for some reason, then the identifier may be constructed at
run-time and the object can be referenced as a property of some object.
For example, consider the following variables to be global:
var object1 = {},
object2 = {},
object3 = {};
As such, they are properties of the global object. This can be
referenced using the this operator (outside the scope of methods -
functions called as properties of an object - and constructor
functions), or the window object in browsers:
for (var i = 1; i <= 3; ++i) {
// Do something with: this["object" + i]
}
Mike