0

I'm attempting to run a list of strings through an object. When I do it individually it works, but when I pass it through as a string it doesn't work. How would I fix this?

// this doesn't work
var a = "IntegrationItem1";
var data = faq.a; 

// but this works
var data = faq.IntegrationItem1; 

What's causing the first example to not work? Is the variable data seeing it as faq."IntegrationItem1" instead of faq.IntegrationItem1?

Question
  • 25
  • 3

2 Answers2

0

You can access properties of the object using it's names:

var a = "IntegrationItem1";
var data = faq[a];
Samich
  • 29,157
  • 6
  • 68
  • 77
  • Good documentation on this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#Bracket_notation – John Ellmore Nov 09 '17 at 23:05
0

what you need is faq["IntegrationItem1"] => faq[a]

Avinash
  • 779
  • 7
  • 18