0

I want to call a JSON value by giving the key via a variable.

Given if (data[airplane].RunwayThreshold !== undefined){}

Can I make RunwayThreshold a variable?

1 Answers1

0

You can chain bracket access:

data[airplane][RunwayThreshold]

although you may want to check for undefined values along the chain.

Because access is left-associative, that becomes:

(data[airplane])[RunwayThreshold]

and allows you to drill down into objects.

Community
  • 1
  • 1
ssube
  • 47,010
  • 7
  • 103
  • 140