【发布时间】:2013-07-03 12:13:46
【问题描述】:
当我通过 ajax 调用 console.log data 时,我得到了这个日志:
Object {next_id: null, images: Array[0]}
images: Array[0]
next_id: null
__proto__: Object
所以我的对象不是0 也不是空的。我想编写一个 if 语句,当 data(作为对象)返回具有 0 数组的属性 images 时运行。
类似:
if (data:images === [0])
其中data 是jQuery 对象,images 是该对象的属性。
【问题讨论】:
-
[0]是数组的大小,而不是内容。 -
如果您要检查
images是否为空数组,请使用if(data.images.length===0)。如果您要检查它是否是一个数组,其中一个元素是数字0,请使用if(data.images.length===1 && data.images[0]===0)。
标签: jquery arrays object properties