I’m looking for a cross-browser-compliant Javascript equivalent to Rails’ Object.blank? (and its counterpart, Object.present?) that returns true for empty objects, empty arrays, empty strings, and null and undefined values. Has anyone seen such a thing? I could write it myself but I know there are some IE gotchas and I figure someone else has probably already tackled this.
I’m looking for a cross-browser-compliant Javascript equivalent to Rails’ Object.blank? (and its counterpart, Object.present?)
Share
I just whipped this together. Have not testing it on any browsers, just ran it in Node.js. But I think it should work.
So…
edit: added a catch so that true and false come back as not blank. If you want false to be considered blank then change that.
edit 2: last change! preventing blank(0) from returning true. But allowing NaN to be considered blank.