Topic Description

Given an object or an array, determine if it is empty. Here are the definitions of "empty":

You can assume the object or array is obtained via JSON.parse.

// Example 1:
Input: obj = {"x": 5, "y": 42}
Output: false
Explanation: This object has two key-value pairs, so it is not empty.

// Example 2:
Input: obj = {}
Output: true
Explanation: This object has no key-value pairs, so it is empty.

Answer

function isEmpty(obj) {
    return Object.keys(obj).length === 0
};