To do this in any ES5-compatible environment, such as Node.js, Chrome, Internet Explorer 9+, Firefox 4+, or Safari 5+:
Object.keys(obj).length
- Browser compatibility
- Object.keys documentation (includes a method you can add to non-ES5 browsers)
More Related Contents:
- What is the difference between properties and attributes in HTML?
- How to create an object property from a variable value in JavaScript? [duplicate]
- How do I reference a JavaScript object property with a hyphen in it?
- When to use Vanilla JavaScript vs. jQuery?
- Declaring multiple variables in JavaScript
- Controlling fps with requestAnimationFrame?
- regex.test V.S. string.match to know if a string matches a regular expression
- How to set a Javascript object values dynamically?
- Access object properties within object [duplicate]
- Should CSS always precede Javascript?
- Javascript when to use prototypes
- Does use of anonymous functions affect performance?
- How to avoid freezing the browser when doing long-running computations in Javascript
- Watch for object properties changes in JavaScript [duplicate]
- Why is bind slower than a closure?
- Get all user defined window properties?
- Is there a performance difference between ‘let’ and ‘var’ in JavaScript
- v8 JavaScript performance implications of const, let, and var?
- Object.keys() complexity?
- Count duplicates within an Array of Objects
- JavaScript object detection: dot syntax versus ‘in’ keyword
- JavaScript performance difference between double equals (==) and triple equals (===)
- Best way to execute js only on specific page
- Determine if a JavaScript property has a getter or setter defined?
- Why Array.forEach is slower than for() loop in Javascript? [duplicate]
- Does the tag position in HTML affects performance of the webpage?
- setTimeout() with string or (anonymous) function reference? speedwise [closed]
- Javascript (jQuery) performance measurement and best practices (not load time)
- How browser executes Javascript and renders asynchronously
- Are there limits to the number of properties in a JavaScript object?