Jquery 检查数组值是否为空
我正在尝试检查数组Jquery 检查数组值是否为空,jquery,ajax,if-statement,Jquery,Ajax,If Statement,我正在尝试检查数组beda[I].person.name值是否为空。但它一直忽视它。我不知道我在用if语句做什么错事 $.ajax({ 网址:link, 方法:“GET”, 成功:功能(beda){ 控制台日志(beda); 对于(变量i=0;i
beda[I].person.name
值是否为空。但它一直忽视它。我不知道我在用if语句做什么错事
$.ajax({
网址:link,
方法:“GET”,
成功:功能(beda){
控制台日志(beda);
对于(变量i=0;i”+beda[i].person.name+“…”+beda[i].character.name+“”);
console.log(beda[i].person.name)
if(beda[i].person.name=''| | beda[i].person.name==null | | beda[i].person.name==未定义的| | beda[i].person.name.lenght==0){
$(“ul”).first();
}
}
}
});
问题是因为您的打字错误<代码>长度应为长度
还请注意,您可以使用类型强制来简化if
语句:
if (!beda[i].person.name) {
$("ul").first().append("<li>" + "No names found!" + "</li>");
}
if(!beda[i].person.name){
$(“ul”).first();
}
问题是因为您的打字错误<代码>长度应为长度
还请注意,您可以使用类型强制来简化if
语句:
if (!beda[i].person.name) {
$("ul").first().append("<li>" + "No names found!" + "</li>");
}
if(!beda[i].person.name){
$(“ul”).first();
}
console.log(beda[i].person.name)
您将了解我的代码中已经有了哪些内容。console.log(beda[i].person.name)
您将了解我的代码中已经有了哪些内容。我尝试过您的解决方案,但仍然不起作用。我尝试过您的解决方案,但仍然不起作用。