Posted By

vaibhav011286 on 10/04/11


Tagged


Versions (?)

detect any type of empty var in JS


 / Published in: JavaScript
 

  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  

You need to login to post a comment.