jquery - Javascript: How to test if response JSON array is empty -
i'm getting following json:
{"array":[],"object":null,"bool":false}
and i'm testing following, seemingly exhaustive, if statement:
$.ajax({ type: "get", url: "/ajax/rest/siteservice/list", datatype: "json", success: function (response) { var sitearray = response.array; // handle case user may not belong groups if (sitearray === null || sitearray=== undefined || sitearray=== '' || sitearray.length === 0) { window.alert('hi'); } } });
but alert not firing. :[
use $.isarray() check whether object array. can check truthness of length
property see whether empty.
if( !$.isarray(sitearray) || !sitearray.length ) { //handler either not array or empty array }
Comments
Post a Comment