【问题标题】:Calling a JSON Value by giving the key as variable?通过将键作为变量来调用 JSON 值?
【发布时间】:2016-05-27 16:31:46
【问题描述】:

我想通过变量给出键来调用 JSON 值。

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

我可以将 RunwayThreshold 设为变量吗?

【问题讨论】:

    标签: javascript json oop


    【解决方案1】:

    您可以链接括号访问:

    data[airplane][RunwayThreshold]
    

    尽管您可能想要检查链中未定义的值。

    因为访问权限是left-associative,所以变成:

    (data[airplane])[RunwayThreshold]
    

    并允许您深入了解对象。

    【讨论】:

      猜你喜欢
      • 2015-04-09
      • 1970-01-01
      • 2014-06-05
      • 2016-08-06
      • 2016-07-20
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 2013-10-02
      相关资源
      最近更新 更多