Javascript Check Json Output Is Empty
If I have data in json like this : {'items':[{'id':'2049','channel_code':'HBD','channel_name':'HBO HD'}]} And if you search my data to the server could not find results like this
Solution 1:
To check whether your array is empty, just use the respective length
property:
if ( data['items'].length < 1 ) {
// it's empty
}
Solution 2:
You want to check if data.items.length > 0
. Assuming
var data = {"items":[]};
Solution 3:
for (member in data) {
if (data[member] != null)
//Do something
}
code inside for
will not run because length
of data is 0
if (myObject == '') {
alert('this object is empty');
}
myObject wont be null because the object actually is there and its an empty array
you should check for myObject.length
because its an empty array
Post a Comment for "Javascript Check Json Output Is Empty"