Skip to main content

javascript-object-check-if-empty

#post

Check if a JavaScript Object is Empty

  • You can’t do a truthy check, since !{} === true
  • Instead, check if !Object.keys(obj).length or Object.keys(obj).length !== 0

Inbox


  • separate til for each “truthy gotcha” I’ve encountered (e.g. also watch out for legit 0 values)?
  • or single post for a few truthy gotchas?
  • tldr: truthiness checks are nice and short, but can sometimes be buggy so be careful!