I'm having trouble extracting an array from a JSON object and checking if it's empty. Here is the relevant HTML:
<p id="r"></p>
And here is the JavaScript code:
var r = document.getElementById('r');
var obj = {
"_id": "4345356",
"title": "sdfsf",
"data": []
};
obj = JSON.parse(obj);
function checkEmptyArray(a) {
if (typeof a === 'undefined' || a.length == 0)
return true;
return false;
}
r.innerHTML = checkEmptyArray(obj.data);
If you have any insights, please visit this Fiddle. Thank you!