{"id":1191,"date":"2013-03-04T22:35:56","date_gmt":"2013-03-05T04:35:56","guid":{"rendered":"http:\/\/bateru.com\/news\/?p=1191"},"modified":"2018-06-30T22:27:20","modified_gmt":"2018-07-01T04:27:20","slug":"code-of-the-day-javascript-check-if-an-object-is-empty","status":"publish","type":"post","link":"https:\/\/bateru.com\/news\/2013\/03\/code-of-the-day-javascript-check-if-an-object-is-empty\/","title":{"rendered":"Code of the day: Javascript check if an object is empty"},"content":{"rendered":"<p>`isObjectEmpty()` is a function that will only return true if the passed an object that contains no keys.<br \/>\nThis is different than jQuery.isEmptyObject() because the passed argument MUST be an object.<br \/>\n<code><\/p>\n<pre lang='javascript'>\r\n\/**\r\n* Check to see if an object has any keys.\r\n* @param {Object} obj\r\n* @return {Boolean}\r\n* @author Larry Battle <bateru.com\/news>\r\n* @license WTFPL\r\n**\/\r\nvar isObjectEmpty = function( obj ) {\r\n\tvar name;\r\n\tfor ( name in obj ) {\r\n\t\treturn false;\r\n\t}\r\n\treturn obj != null && typeof obj === \"object\";\r\n};\r\n<\/pre>\n<p><\/code><\/p>\n<p><iframe style=\"width: 100%; height: 300px\" src=\"https:\/\/jsfiddle.net\/GXJDN\/embedded\/\" allowfullscreen=\"allowfullscreen\" frameborder=\"0\"><\/iframe><\/p>\n","protected":false},"excerpt":{"rendered":"<p>`isObjectEmpty()` is a function that will only return true if the passed an object that contains no keys. This is different than jQuery.isEmptyObject() because the passed argument MUST be an object. \/** * Check to see if an object has any keys. * @param {Object} obj * @return {Boolean} * @author Larry Battle * @license &hellip; <a href=\"https:\/\/bateru.com\/news\/2013\/03\/code-of-the-day-javascript-check-if-an-object-is-empty\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Code of the day: Javascript check if an object is empty<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,10],"tags":[30,20,164,253],"class_list":["post-1191","post","type-post","status-publish","format-standard","hentry","category-frontend-tech","category-tutorials","tag-code-of-the-day","tag-demo","tag-javascript","tag-object-has-keys"],"_links":{"self":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/1191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/comments?post=1191"}],"version-history":[{"count":2,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/1191\/revisions"}],"predecessor-version":[{"id":1538,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/posts\/1191\/revisions\/1538"}],"wp:attachment":[{"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/media?parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/categories?post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bateru.com\/news\/wp-json\/wp\/v2\/tags?post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}