当我console.log
data
从AJAX调用我得到这个日志:检查对象的属性,使其具有零阵列
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]'是数组的大小,而不是内容。 – Barmar
如果你想检查'images'是否是一个空数组,使用'if(data.images.length === 0)'。如果你试图检查它是否是一个数组为'0'的数组,使用if(data.images.length === 1 && data.images [0] === 0)'。 – nnnnnn