1

how can I display string representation of a variable and not the value it contains.

I know eval can take string and evaluate to a variable but what's the other way?

user2727195
  • 7,122
  • 17
  • 70
  • 118

1 Answers1

0

It seems you are asking about property names, not variable names.

If you are getting an array of property names and you have a reference to the related object, you can use square bracket notation to access the named properties of the object:

var obj = {foo: '...', bar: '...', ...};
var propertyNames = ['foo', 'bar', ...];

for (var i=0, iLen=propertyNames.length; i<iLen; i++) {

    if (obj[propertyNames[i]] == someValue) {
      // do stuff

    } else {
      // do other stuff
    }
}
RobG
  • 142,382
  • 31
  • 172
  • 209