我需要查明 id 是否出现在我的 JSON 对象中,例如:
{
"requested": "2009-07-25T14:12:25+01:00",
"channels": [
{"id": 1, "name": "General", "created": "2009-07-25 14:00:02"}
]
}
具体来说,我需要检查我的 id(例如 2)是否出现在 channel 中。
i
.id
。如何做到这一点?
最佳答案
试试这个:
var id = 2,
found = false;
for (var i=0; i<channels.length; i++) {
if (channels[i].id == id) {
found = true;
break;
}
}
关于javascript - 检查 JSON 对象中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1182082/