Check if array is empty or null

后端 未结 4 582
灰色年华
灰色年华 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:53

    User JQuery is EmptyObject to check whether array is contains elements or not.

    var testArray=[1,2,3,4,5];
    var testArray1=[];
    console.log(jQuery.isEmptyObject(testArray)); //false
    console.log(jQuery.isEmptyObject(testArray1)); //true
    

提交回复
热议问题