How to match an empty dictionary in Javascript? How to match an empty dictionary in Javascript? javascript javascript

How to match an empty dictionary in Javascript?


function isEmpty(obj) {  return Object.keys(obj).length === 0;}


You could extend Object.prototype with this isEmpty method to check whether an object has no own properties:

Object.prototype.isEmpty = function() {    for (var prop in this) if (this.hasOwnProperty(prop)) return false;    return true;};


How about using jQuery?

$.isEmptyObject(d)