How to check a object is empty or null? (Javascript)
That code block is object check for empty or null control.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var test = {}; | |
if (test==null && isEmpty(test)) { | |
console.log("is empty"); | |
} else { | |
console.log("is not empty"); | |
} | |
function isEmpty(obj) { | |
for (var key in obj) { | |
if (obj.hasOwnProperty(key)) | |
return false; | |
} | |
return true; | |
} |
Yorumlar
Yorum Gönder