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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -