Check if Object of Arrays is Empty in Javascript

May 25, 2019 — Leave a comment

The problem I had was an object with empty arrays in it. If I just checked if the Object is empty, I would’ve gotten a false, because there are arrays.

So we had to iterate through the object, and check if the length of the array is greater than 0. The some function will return true as soon as any key returns greater than 0.

let obj = {
    a: [],
    b: [],
    c: []
Object.keys(obj).some(key => obj[key].length !== 0)


Posts Twitter Facebook

My name is Michael Le, and I am a web developer.

No Comments

Be the first to start the conversation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.