【发布时间】:2016-07-21 07:41:51
【问题描述】:
我从服务中获得以下 JSON 结构:
{
"prop": [
{
"key": "FOO",
"value": "Foo is wonderfull, foo is great"
},
{
"key": "BAR",
"value": "Bar is bad, really bad"
}
]
}
我需要一个函数,它作为参数,例如BAR 并输出“Bar is bad,..”,我该如何实现?欢迎使用 Lodash/下划线或 VanillaJS。
【问题讨论】:
-
您可以遍历您的
prop数组并在每次交互中获取key属性,将其与传递给您的函数的参数进行比较,如果匹配则返回value属性。跨度>
标签: javascript json underscore.js lodash