我有一个多维数组,我想检查其中是否有值。我已经尝试过Array.includes("value")
,但没有任何反应。这是我的代码:
var database = [{
"identifier": "test1",
"extra": "information1"
},{
"identifier": "test2",
"extra": "information2"
},{
"identifier": "test3",
"extra": "information3"
}
]
如何测试"identifier"
是否在数组中?
谢谢!
答案 0 :(得分:-1)
hi,请参见下面的代码,该代码读取数据库的每个元素并打印每个元素的“标识符”值。
var database = [{
"identifier": "test1",
"extra": "information1"
},{
"identifier": "test2",
"extra": "information2"
},{
"identifier": "test3",
"extra": "information3"
}
]
$.each(database, function(index, value) {
if(value.identifier.length>0)
console.log(value.identifier);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>