Mittwoch, 2. Juni 2010

Using Objects Maps

Say you have a lot of variables a1,a2, ... an and have a number x=5 to select the ax variable.

using Objects as a map you can do this quite easily:

var obj = {
a1 = a1,
a2 = a2,

an = an
};
var chosen = obj["a"+x];


Now chosen contains the ax variable.

Keine Kommentare:

Kommentar veröffentlichen