0

I have an array called config, in this array I have pushed several variables/objects (I'm not sure if variable or object is the correct term here) like this:

var config = [];

var example1 = { x : 12, y : 5 };
var example2 = { x : 17, y : 4 };
var example3 = { x : 11, y : 9 };

config.push(example1);
config.push(example2);
config.push(example3);

Now I want to get the names of all these variables/objects and do a console.log of their names. I have tried the following:

for(i = 0; i < config.length; i++)
{
    console.log(config[i].constructor.name);
}

How do I get just the name of the variable/object? I don't want any of it's attributes or values, only the name. The loop should simply log to the console like:

example1
example2
example3
cenh
  • 154
  • 13
  • You can not get those. `example1` (and others) are just reference to the objects. If you want to add a name, put a `name` field in the object. You added the objects to the array, not the variable names. – vaso123 May 17 '16 at 10:23
  • here example1 and all for just referring the variable itself and you push the value of example1 into the list not an example1 etc... so, if u want example1 , try to insert as a key, value pair – Mohideen bin Mohammed May 17 '16 at 10:25

0 Answers0