Marc Marc - 1 year ago 90
JSON Question

Calling a JSON Value by giving the key as variable?

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


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

Can I make RunwayThreshold a variable?

Answer Source

You can chain bracket access:


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

Because access is left-associative, that becomes:


and allows you to drill down into objects.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download