这是我的JSON对象,我需要检查特定的 id 并获取日期
r2 <- raster(nrows =1, ncols =2)
r2[] <- c(1, 2)
levelplot(r2, margin = FALSE)
答案 0 :(得分:0)
find
根据条件获取具体内容。此替代方法仅使用逻辑运算符||
来避免对未定义值的访问错误。
var array = [{
"id": "9b3b835b",
"date": "Tue Mar 27 10:23:18 UTC 2018"
},
{
"id": "57eab193",
"date": "Thu Mar 29 14:45:23 UTC 2018"
},
{
"id": "440f0cd9",
"date": "Thu Mar 29 15:12:00 UTC 2018"
},
];
var date = (array.find(o => o.id === "440f0cd9") || {}).date;
console.log(date);
date = (array.find(o => o.id === "ele") || {}).date;
console.log(date);
&#13;
答案 1 :(得分:0)
yourVariable = [{
"id": "9b3b835b",
"date": "Tue Mar 27 10:23:18 UTC 2018"
},
{
"id": "57eab193",
"date": "Thu Mar 29 14:45:23 UTC 2018"
},
{
"id": "440f0cd9",
"date": "Thu Mar 29 15:12:00 UTC 2018"
},
];
for (keys in yourVariable) {
// supposing id your are looking for is 57eab193
if (yourVariable[keys].id == '57eab193') {
console.log(yourVariable[keys].date)
}
}