isObjectEmpty

Easy · Object Manipulation · 2 test cases

Given an object, return true if it has no properties, and false otherwise.

Examples

isObjectEmpty({}) → true
isObjectEmpty({a: 1}) → false

Starter code

function isObjectEmpty(obj) {

}

Complexity of the optimal solution

Time O(n), space O(n). This method relies on `Object.keys()`, which creates an array of the object's keys. The time and space for this are O(n). A more optimal O(1) solution exists using a for...in loop and returning immediately.

Solve isObjectEmpty in the browser