Sorry, I know this is programming 101, but I can't find any good documentation...
I have an array, and I want to cast each member as an object and then call them by the name assigned (this would be so much simpler if javascript allowed for non-number index values). For instance:
var things = ['chair', 'tv', 'bed'];
var costs = ['10', '100', '75'];
for (var i = 0; i < things.length; i++) {
thing.name = things[i];
thing.cost = costs[i];
}
alert(thing.name('tv').cost);
Obviously this isn't the way to do this, but the desired outcome would be an alert that said "100".
I have gotten as far as creating a class that has a method called name which points back to the main object, like so:
function thing(name, cost) {
function name(thename) {
return this;
}
this.thingname = name;
this.name = name;
this.cost = cost;
}
But this still requires that each object has a unique variable name, which goes against the whole point. What I want is to simply throw all of my array into some generic class and call the values I need by the name.
I know this is probably way to easy to ask here, but I'm stuck!
Thanks.