【发布时间】:2016-05-27 16:31:46
【问题描述】:
我想通过变量给出键来调用 JSON 值。
鉴于
if (data[airplane].RunwayThreshold !== undefined){}
我可以将 RunwayThreshold 设为变量吗?
【问题讨论】:
标签: javascript json oop
我想通过变量给出键来调用 JSON 值。
鉴于
if (data[airplane].RunwayThreshold !== undefined){}
我可以将 RunwayThreshold 设为变量吗?
【问题讨论】:
标签: javascript json oop
您可以链接括号访问:
data[airplane][RunwayThreshold]
尽管您可能想要检查链中未定义的值。
因为访问权限是left-associative,所以变成:
(data[airplane])[RunwayThreshold]
并允许您深入了解对象。
【讨论】: