Check if array is empty or null

后端 未结 4 590
灰色年华
灰色年华 2020-12-22 23:13

I would like to know how to check if an array is empty or null in jQuery. I tried array.length === 0 but it didn\'t work. It did not throw any error either.

4条回答
  •  醉酒成梦
    2020-12-22 23:59

    I think it is dangerous to use $.isEmptyObject from jquery to check whether the array is empty, as @jesenko mentioned. I just met that problem.

    In the isEmptyObject doc, it mentions:

    The argument should always be a plain JavaScript Object

    which you can determine by $.isPlainObject. The return of $.isPlainObject([]) is false.

提交回复
热议问题