0

当我console.log data从 ajax 调用中得到这个日志时:

Object {next_id: null, images: Array[0]}
images: Array[0]
next_id: null
__proto__: Object

所以我的对象不是0空的。我想编写一个 if 语句,当data(作为对象)返回images具有 0 数组的属性时运行。

就像是:

if (data:images === [0])

其中data是 jQuery 对象和images该对象的属性。

4

2 回答 2

0

try

if (data.images.length === 0)

You can access methods and properties through . symbol. And you can check the array length.

于 2013-07-05T11:45:31.637 回答
0

If I understood you well, you can try:

if (data.images.lenght === 0) {
    // no elements
}
于 2013-07-05T11:46:17.177 回答