detect any type of empty var in JS


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function empty(a) {
  2. if (a === "" || a === 0 || a === null || a === 'null' || a === 'undefined' || a === !1 || typeof a === "undefined") return !0;
  3. if (typeof a === "object") if (a instanceof Array) return a.length === 0;
  4. else {
  5. for (var b in a) return !1;
  6. return !0
  7. }
  8. if (typeof a === "string") return a.length === 0
  9. }
  10.  
  11. //it detects any type of empty var in JS like array, object, string, number etc..

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.