javascript - check if object is empty

前端 未结 5 1012
感情败类
感情败类 2021-02-05 08:57

I am trying to create to javascript/jquery test to check if my object is empty and cannot figure it out.

Here is the object when it has something in it:

         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 09:30

    Here is in jQuery:

    $(document).ready(function(){
    	var obj={"mergedSellerArray":{}};
    	alert("is empty: "+$.isEmptyObject(obj.mergedSellerArray));
    
            var obj2={"mergedSellerArray":{"key1114":"1120"}};
    	alert("is empty: "+$.isEmptyObject(obj2.mergedSellerArray));
    })

    jsfidle: https://jsfiddle.net/nyqgbp38/

提交回复
热议问题