// because Object.keys(new Date()).length === 0; // we have to do some additional check obj // đ null and undefined check && Object.keys(obj).length === 0 && Object.getPrototypeOf(obj) === Object.prototype
Note, though, that this creates an unnecessary array (the return value of keys
).
Pre-ECMA 5:
function isEmpty(obj) { for(var prop in obj) { if(Object.prototype.hasOwnProperty.call(obj, prop)) { return false; } } return JSON.stringify(obj) === JSON.stringify({}); }
jQuery.isEmptyObject({}); // true
_.isEmpty({}); // true
_.isEmpty({}); // true
Hoek.deepEqual({}, {}); // true
Ext.Object.isEmpty({}); // true
angular.equals({}, {}); // true
R.isEmpty({}); // true
Related Posts:
- Whatâs the difference between â{}â and â[]â while declaring a JavaScript array?
- How do I check if an array includes a value in JavaScript?
- Find object by id in an array of JavaScript objects
- How can I merge properties of two JavaScript objects dynamically?
- How do I test for an empty JavaScript object?
- How do I correctly clone a JavaScript object?
- How can I display a JavaScript object?
- Length of a JavaScript object
- Cannot read property ‘style’ of undefined — Uncaught Type Error
- How do I check whether a checkbox is checked in jQuery?
- SyntaxError: Unexpected token o in JSON at position 1
- What does the function then() mean in JavaScript?
- Understanding unique keys for array children in React.js
- (Google Map API) Geocode was not successful for the following reason: REQUEST_DENIED
- Generate random number between two numbers in JavaScript
- What is an unhandled promise rejection?
- What is a good regular expression to match a URL? [duplicate]
- How can I get the data-id attribute?
- document.getElementById vs jQuery $()
- How to import jquery using ES6 syntax?
- How to filter an array/object by checking multiple values
- How to randomize (shuffle) a JavaScript array?
- How to pass props to {this.props.children}
- Adding options to select with javascript
- What is the most efficient way to deep clone an object in JavaScript?
- Loading local JSON file
- How to check all checkboxes using jQuery?
- Accessing elements by type in JavaScript
- What is the most efficient way to deep clone an object in JavaScript?
- RegExp in TypeScript
- How to use searchFile and searchFolder at the same time correctly? – App Script
- Full-screen iframe with a height of 100%
- Change CSS of class in Javascript?
- keycode 13 is for which key
- SyntaxError: ‘import’ and ‘export’ may appear only with ‘sourceType: module’ – Gulp
- Get the value of checked checkbox?
- Equivalent of jQuery .hide() to set visibility: hidden
- How can I get the last character in a string?
- Create table using Javascript
- Parse an HTML string with JS
- JS file gets a net::ERR_ABORTED 404 (Not Found)
- Error: Cannot find module html
- Is it possible to append to innerHTML without destroying descendants’ event listeners?
- How to add an object to an array
- Finding the average of an array using JS
- Is it possible to simulate key press events programmatically?
- Vue template or render function not defined yet I am using neither?
- Cannot read property ‘length’ of null (javascript)
- How to connect signalR from angularJs
- How can I copy to clipboard in HTML5 without using flash?
- how to get the value of a textarea in jquery?
- Maximum call stack size exceeded on npm install
- Return array from function
- Why define an anonymous function and pass it jQuery as the argument?
- How to run a function when the page is loaded?
- RegEx: How can I match all numbers greater than 49?
- Multiple left-hand assignment with JavaScript
- Disabled href tag
- How to get child element by class name?
- TypeError getElementsByTagName is not a function issue
- Creating Accordion Table with Bootstrap
- Creating Multiple Modals on a Single Page
- How to check if the URL contains a given string?
- Check if url contains string with JQuery
- what is the best way to check variable type in javascript
- What’s the equivalent of Java’s Thread.sleep() in JavaScript?
- wp_enqueue_script isn’t connecting my custom js file
- What do the args for Gutenberg subpackage “hooks” function “doAction” mean?
- How do I fire a snackbar notice in admin?
- How/Where is editor.min.js Added to the wp-admin Post Page?
- Should a WordPress plugin polyfill the global JS environment?
- Close TinyMCE plugin window on click away
- Running JS after theme customizer finished initialization
- Hide reply button after moveForm is called
- How to add custom javascript into from custom plugin
- remove inline scripts from the_content() produced by plugins?
- Help display image in single post using javascript zoom image..?
- Checks when fetching data from multiple REST API endpoints in Gutenberg
- How to get the title of the item that is clicked on
- Correct way to include extra styles & script files?
- Correctly enqueue scripts of type=text/paperscript (PaperJs Library)
- useSelect second parameter
- How can I allow HTML in Gutenberg UI elements help text?
- How do I make my wordpress post appear in a mouse hover preview?
- UnitControl – Block has encountered an error
- Should I manually resolve WP Core File security issues or await a subsequent WP release?
- jQuery UI Tools: Scrollable: More than 1 instance possible?
- Uncaught TypeError: switchEditors.switchto is not a function
- Check if user can in javascript
- Rest API and how to deal with it in server side
- Is it possible to override only a part of another plugin’s / theme’s js (asset) file?
- VisualComposer/WPBakery Page Editor: Is any JS event triggered after the Edition pop-in is shown?
- How do I integrate a codepen?
- Can I just insert JavaScript by using ?
- Gutenberg Edit Block Inspector Controls and save
- JavaScript and Google PageSpeed + wp_enqueue_script
- How to modify a class in load-scripts.js ?
- Trigger a function during onload
- Add Javascript/Html into a WordPress
- Google AdSense Ad not showing up in WordPress Blog [closed]