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:
{"mergedSellerArray":{"key1114":"1120"}}
And here is the object when empty:
{"mergedSellerArray":{}}
This is the current test I have based on another SO answer but it does not work:
var sellers = JSON.stringify({mergedSellerArray});
if(Object.keys(sellers).length === 0 && sellers.constructor === Object) {
console.log("sellers is empty!");
}
sellers?sellersis the outer object, then it isn't empty, and you'll have to write some code to check that it matches your expected state.JSON.stringify()turns the object into a string, as the name suggests. What's the point of thesellersvariable anyway? Why can't you just checkmergedSellerArrayas is?