我试图检查一个值是否存在于对象数组中。
上面的代码片段在
function hasProperties(id){
jQuery(JSON.parse(jQuery("#PropertiesField").html())).each(function () {
if(id== jQuery(this)[0].properties.id) {
console.log((id== jQuery(this)[0].properties.id));
return "Present";
}
})
};
var something = hasProperties("someid");
上面的代码片段在
something
上返回了undefined
,但是在控制台中也输出了true。为什么当条件满足时它没有返回present
,我犯了什么错误?
this.id
。 - void