How to match an empty dictionary in Javascript?

João Pinto Jerónimo picture João Pinto Jerónimo · May 20, 2011 · Viewed 60.9k times · Source

From the node REPL thing,

> d = {}
{}
> d === {}
false
> d == {}
false

Given I have an empty dictionary, how do I make sure it is an empty dictionary ?

Answer

Raynos picture Raynos · May 20, 2011
function isEmpty(obj) {
  return Object.keys(obj).length === 0;
}