{"id":40,"date":"2015-10-06T18:04:37","date_gmt":"2015-10-06T23:04:37","guid":{"rendered":"https:\/\/azoreancoder.pw\/blog\/?p=40"},"modified":"2015-12-25T02:31:05","modified_gmt":"2015-12-25T07:31:05","slug":"js-quick-function-to-check-if-an-object-is-empty","status":"publish","type":"post","link":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty","title":{"rendered":"[JS] Quick function to check if an object is empty"},"content":{"rendered":"<p>Checking for an empty object in Javascript is doable, but rather interesting. See, I&#8217;m used to EXT Js having everything built in, but that isn&#8217;t always the case. For example, we have Ext.isEmpty, but in version 5, it doesn&#8217;t know any better, it basically only checks for strings and numbers (Possibly NaNs and what have you in version 6? )<\/p>\n<p><pre id=\"code\"><code class=\"language-javascript\">function isEmptyObject( object ){\r\n    for ( item in object ) {\r\n        return false;\r\n    }\r\n    return true;\r\n}<\/code><\/pre><br \/>\nAnd voila&#8217;!<\/p>\n<p>This is basically a loop that checks every item\u00a0stops at the first one it finds, be it a function, variable, etc.. it returns false\u00a0immediately. But if it\u00a0this for loop doesn&#8217;t even have ONE iteration it&#8217;ll just return true. Returning\u00a0anything usually stops a function immediately.<\/p>\n<p>Hope this is as useful to you as it was to me!<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Checking for an empty object in Javascript is doable, but rather interesting. See, I&#8217;m used to EXT Js having everything built in, but that isn&#8217;t always the case. For example, we have Ext.isEmpty, but in version 5, it doesn&#8217;t know any better, it basically only checks for strings and numbers (Possibly NaNs and what have&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":81,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,10],"tags":[18,19,20],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[JS] Quick function to check if an object is empty - Azoreancoder<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[JS] Quick function to check if an object is empty - Azoreancoder\" \/>\n<meta property=\"og:description\" content=\"Checking for an empty object in Javascript is doable, but rather interesting. See, I&#8217;m used to EXT Js having everything built in, but that isn&#8217;t always the case. For example, we have Ext.isEmpty, but in version 5, it doesn&#8217;t know any better, it basically only checks for strings and numbers (Possibly NaNs and what have... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty\" \/>\n<meta property=\"og:site_name\" content=\"Azoreancoder\" \/>\n<meta property=\"article:published_time\" content=\"2015-10-06T23:04:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2015-12-25T07:31:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/azoreancoder.pw\/blog\/wp-content\/uploads\/2015\/10\/header1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"550\" \/>\n\t<meta property=\"og:image:height\" content=\"210\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"madcat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@madcat1990\" \/>\n<meta name=\"twitter:site\" content=\"@madcat1990\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"madcat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty\",\"url\":\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty\",\"name\":\"[JS] Quick function to check if an object is empty - Azoreancoder\",\"isPartOf\":{\"@id\":\"https:\/\/azoreancoder.pw\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#primaryimage\"},\"image\":{\"@id\":\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#primaryimage\"},\"thumbnailUrl\":\"https:\/\/azoreancoder.pw\/blog\/wp-content\/uploads\/2015\/10\/header1.png\",\"datePublished\":\"2015-10-06T23:04:37+00:00\",\"dateModified\":\"2015-12-25T07:31:05+00:00\",\"author\":{\"@id\":\"https:\/\/azoreancoder.pw\/blog\/#\/schema\/person\/963b49b188d6021584d791ad298f41d1\"},\"breadcrumb\":{\"@id\":\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#primaryimage\",\"url\":\"https:\/\/azoreancoder.pw\/blog\/wp-content\/uploads\/2015\/10\/header1.png\",\"contentUrl\":\"https:\/\/azoreancoder.pw\/blog\/wp-content\/uploads\/2015\/10\/header1.png\",\"width\":550,\"height\":210,\"caption\":\"Object error message\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/azoreancoder.pw\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[JS] Quick function to check if an object is empty\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/azoreancoder.pw\/blog\/#website\",\"url\":\"https:\/\/azoreancoder.pw\/blog\/\",\"name\":\"Azoreancoder\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/azoreancoder.pw\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/azoreancoder.pw\/blog\/#\/schema\/person\/963b49b188d6021584d791ad298f41d1\",\"name\":\"madcat\",\"sameAs\":[\"https:\/\/instagram.com\/madcat1990\",\"https:\/\/x.com\/madcat1990\"],\"url\":\"https:\/\/azoreancoder.pw\/blog\/archives\/author\/madcat\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[JS] Quick function to check if an object is empty - Azoreancoder","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty","og_locale":"en_US","og_type":"article","og_title":"[JS] Quick function to check if an object is empty - Azoreancoder","og_description":"Checking for an empty object in Javascript is doable, but rather interesting. See, I&#8217;m used to EXT Js having everything built in, but that isn&#8217;t always the case. For example, we have Ext.isEmpty, but in version 5, it doesn&#8217;t know any better, it basically only checks for strings and numbers (Possibly NaNs and what have... Read More","og_url":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty","og_site_name":"Azoreancoder","article_published_time":"2015-10-06T23:04:37+00:00","article_modified_time":"2015-12-25T07:31:05+00:00","og_image":[{"width":550,"height":210,"url":"https:\/\/azoreancoder.pw\/blog\/wp-content\/uploads\/2015\/10\/header1.png","type":"image\/png"}],"author":"madcat","twitter_card":"summary_large_image","twitter_creator":"@madcat1990","twitter_site":"@madcat1990","twitter_misc":{"Written by":"madcat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty","url":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty","name":"[JS] Quick function to check if an object is empty - Azoreancoder","isPartOf":{"@id":"https:\/\/azoreancoder.pw\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#primaryimage"},"image":{"@id":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#primaryimage"},"thumbnailUrl":"https:\/\/azoreancoder.pw\/blog\/wp-content\/uploads\/2015\/10\/header1.png","datePublished":"2015-10-06T23:04:37+00:00","dateModified":"2015-12-25T07:31:05+00:00","author":{"@id":"https:\/\/azoreancoder.pw\/blog\/#\/schema\/person\/963b49b188d6021584d791ad298f41d1"},"breadcrumb":{"@id":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#primaryimage","url":"https:\/\/azoreancoder.pw\/blog\/wp-content\/uploads\/2015\/10\/header1.png","contentUrl":"https:\/\/azoreancoder.pw\/blog\/wp-content\/uploads\/2015\/10\/header1.png","width":550,"height":210,"caption":"Object error message"},{"@type":"BreadcrumbList","@id":"https:\/\/azoreancoder.pw\/blog\/archives\/js-quick-function-to-check-if-an-object-is-empty#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/azoreancoder.pw\/blog"},{"@type":"ListItem","position":2,"name":"[JS] Quick function to check if an object is empty"}]},{"@type":"WebSite","@id":"https:\/\/azoreancoder.pw\/blog\/#website","url":"https:\/\/azoreancoder.pw\/blog\/","name":"Azoreancoder","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/azoreancoder.pw\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/azoreancoder.pw\/blog\/#\/schema\/person\/963b49b188d6021584d791ad298f41d1","name":"madcat","sameAs":["https:\/\/instagram.com\/madcat1990","https:\/\/x.com\/madcat1990"],"url":"https:\/\/azoreancoder.pw\/blog\/archives\/author\/madcat"}]}},"_links":{"self":[{"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/posts\/40"}],"collection":[{"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":9,"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":88,"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/posts\/40\/revisions\/88"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/media\/81"}],"wp:attachment":[{"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/azoreancoder.pw\/blog\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}