Let's say I have an array filled with objects - exactly 10 of them, each with unique names.
var upgrades = [
tree = {price: 20, rate:0.5, owned:0},
irr = {price: 80, rate:1, owned:0},
press = {price: 150, rate:2, owned:0},
cracker = {price: 400, rate:7, owned:0},
gmo = {price: 1000, rate:10, owned:0},
shack = {price: 1500, rate:13, owned:0},
truck = {price: 2000, rate:14, owned:0},
factory = {price: 5000, rate:18, owned:0},
rr = {price: 9000, rate:25, owned:0},
mGadget = {price: 15000, rate:30, owned:0},
];
I would like to extract the name associated with each object and store it in a string variable.
var x=upgrades[0].getObjName
In theory, x should now be equivalent to 'tree'; Is there a way to achieve this without having to introduce a 'name' variable within my objects?