javascript - 通过将键作为变量来调用 JSON 值?

标签 javascript json oop

我想通过变量提供 key 来调用 JSON 值。

给定 if (data[飞机].RunwayThreshold !== 未定义){}

我可以将 RunwayThreshold 设置为变量吗?

最佳答案

您可以通过链式支架访问:

data[airplane][RunwayThreshold]

尽管您可能想检查链上是否有未定义的值。

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

(data[airplane])[RunwayThreshold]

并允许您深入了解对象。

关于javascript - 通过将键作为变量来调用 JSON 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37488388/

相关文章:

Jquery 每个 Json 对象

c# - 接口(interface)是否兼容多态性

javascript - 在 javascript 中使对象成为非全局对象

javascript - 如何连接数组索引以根据索引更改组件的样式?

c# - 跳过潜在的空值 c#

javascript - 使用 AngularJS 获取 JSON

ios - Swift:如何实现协议(protocol)(接口(interface))的部分类实现?

javascript - ES6 中的 AngularJS Controller 继承

javascript - rails : change CSS property dynamically?

javascript - 正则表达式从给定字符串中删除下划线