我有以下对象,我想检查 Type.ID 是否包含值 6508:
{
"item": {
"Feature": [
{
"ID": 85408,
"Status": {
"ID": 65,
},
"Type": {
"ID": 6508,
"Volume": null
},
"Manufacturer": null
},
{
"ID": 85409,
"Status": {
"ID": 65,
},
"Type": {
"ID": 6509,
"Volume": null
},
"Manufacturer": null
}
],
"Errors": {
"Result": 0,
"Message": ""
},
"RecordCount": 2
}
}
我可以集合以下内容:
for (i = 0; i < data.item.Feature.length; i++) {
if (data.item.Feature[i].Type.ID == 6508)
return true;
}
return false;
我如何使用 underscore.js 来做同样的事情?以下不起作用?
_.contains(data.item.Feature.Type.ID, 6508)
最佳答案
你不需要下划线;纯 JS 示例。
data.item.Feature.some(function(x) { return x.Type.ID === 6508 });
关于javascript - Underscore.js - 检查对象数组是否包含值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43165700/