🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › length
Array: length - JavaScript - MDN Web Docs
The length data property of an Array instance represents the number of slots in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array. It may be greater than the number of elements if the array is sparse.
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript length of object
How to Get the Length of Object in JavaScript | Delft Stack
March 11, 2025 - Another efficient way to determine the length of an object is by using the Object.entries() method. Similar to Object.keys(), this method returns an array, but instead of just the keys, it returns an array of the object’s own enumerable string-keyed property [key, value] pairs. By checking the length of this array, you can quickly ascertain how many properties the object has.
Discussions

Length of a JavaScript object - Stack Overflow
I have a JavaScript object. Is there a built-in or accepted best practice way to get the length of this object? More on stackoverflow.com
🌐 stackoverflow.com
ecmascript 6 - Length of Array of Objects in JavaScript - Stack Overflow
However, I'm struggling to find out how can I find the length of all properties contained on an array of objects. More on stackoverflow.com
🌐 stackoverflow.com
typescript - Check array length in object javascript - Stack Overflow
I need to check if any of those array is empty to return true, is this possible to do in one iteration, here is what I have tried for now, but some does not check array length it always return true even if array is empty :( More on stackoverflow.com
🌐 stackoverflow.com
September 29, 2021
console.log(array.length) gives 0 even though array has 6 nums(in render())??
Show the code Holmes More on reddit.com
🌐 r/reactjs
5
1
October 27, 2020
🌐
Medium
medium.com › @python-javascript-php-html-css › determining-the-length-of-a-javascript-object-fc5f9aa39cdc
Finding an Object's Length in JavaScript | by Denis Bélanger
August 24, 2024 - In JavaScript, objects are used to store collections of data, but unlike arrays, objects don’t have a built-in length property. When working with objects, it’s often useful to determine how many properties or key-value pairs they contain.
🌐
Sentry
sentry.io › sentry answers › javascript › how to get the length of a javascript object
How to get the length of a JavaScript object | Sentry
February 15, 2023 - It’s similar to the Object.keys() method in that it returns an array of the properties of an object. The difference is that it also returns non-enumerable properties, except for properties that use a symbol type. const obj = { name: 'Ben', age: 30, job: 'doctor' }; const arrFromObj = Object.getOwnPropertyNames(obj); console.log(arrFromObj.length); // 3
🌐
Stack Overflow
stackoverflow.com › questions › 5223 › length-of-a-javascript-object
Length of a JavaScript object - Stack Overflow
I have a JavaScript object. Is there a built-in or accepted best practice way to get the length of this object? const myObject = new Object(); myObject["firstname"] = "Gareth";
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › find-the-length-of-a-javascript-object
Find the Length of JavaScript object - GeeksforGeeks
To find the length of a JavaScript object using Lodash’s _.size() method, pass the object to _.size(). This function returns the number of own enumerable properties in the object, making it a simple and effective way to determine the object's ...
Published: July 12, 2025
🌐
W3Schools
w3schools.com › jsref › jsref_length_array.asp
JavaScript Array length Property
The length property sets or returns the number of elements in an array.
🌐
Just Academy
justacademy.co › blog-detail › how-to-check-object-length-in-javascript
How to Check Object Length in JavaScript by Roshan Chaturvedi | JustAcademy
By checking the length of an object, ...freeMessage us for more information: +91 99871842961 - Using the .length property: In JavaScript, you can check the length of an object (such as an array or a string) by accessing its length property....
🌐
Scaler
scaler.com › home › topics › how to get the length of an object in javascript?
How to Get the Length of an Object in JavaScript? - Scaler Topics
March 19, 2024 - Understanding how to find the object's length is not a common and basic operation, but in order to avoid unnecessary bugs, it is essential to know how it can be done. There is no length property by default on the object. It is only available to arrays and strings that have the length property. A JavaScript object's length can be determined by either using one of its static methods or by using the for...in loop method.
Find elsewhere
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-get-the-length-of-a-javascript-object.php
How to Get the Length of a JavaScript Object
The Object.keys() method returns an array of a given object's own enumerable property names, and the length property returns the number of elements in that array. Let's take a look at an example to understand how it basically works: ... // Sample ...
🌐
Stack Abuse
stackabuse.com › get-length-of-javascript-object
Get Length of JavaScript Object
November 8, 2023 - The Object.keys() method returns an array of properties of the Object, we will then make use of the length property to get the number of elements in the array (length of the object).
Top answer
1 of 1
1

some is the right method to use, but it's a method, not a flag, so your innermost .some(y => y.buildingUniqueIds.some) will always return true, because a method is a truthy value.

Instead, check length:

const hasEmpties = array.entities.some(({annexes, buildingUniqueIds}) =>
    buildingUniqueIds.length === 0 ||
    annexes.some(({buildingUniqueIds}) => buildingUniqueIds.length === 0)
);

Live Example:

function check(label, array) {
    const hasEmpties = array.entities.some(({annexes, buildingUniqueIds}) =>
        buildingUniqueIds.length === 0 ||
        annexes.some(({buildingUniqueIds}) => buildingUniqueIds.length === 0)
    );
    console.log(label, "=>", hasEmpties);
}

check("all empty", {
    "entities": [
        {
            "annexes": [
                {
                    "buildingUniqueIds": []
                },
                {
                    "buildingUniqueIds": []
                },
                {
                    "buildingUniqueIds": []
                },
            ],
            "buildingUniqueIds": []
        }
    ]
});

check("none empty", {
    "entities": [
        {
            "annexes": [
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": [{}]
                },
            ],
            "buildingUniqueIds": [{}]
        }
    ]
});

check("entities.buildingUniqueIds empty", {
    "entities": [
        {
            "annexes": [
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": [{}]
                },
            ],
            "buildingUniqueIds": []
        }
    ]
});

check("entities.annexes.buildingUniqueIds[1] empty", {
    "entities": [
        {
            "annexes": [
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": []
                },
                {
                    "buildingUniqueIds": [{}]
                },
            ],
            "buildingUniqueIds": [{}]
        }
    ]
});

Side note: If you like, you can use !buildingUniqueIds.length rather than buildingUniqueIds.length === 0.

Or without destructuring if you prefer:

const hasEmpties = array.entities.some(entity =>
    entity.buildingUniqueIds.length === 0 ||
    entity.annexes.some(annex => annex.buildingUniqueIds.length === 0)
);

Live Example:

function check(label, array) {
    const hasEmpties = array.entities.some(entity =>
        entity.buildingUniqueIds.length === 0 ||
        entity.annexes.some(annex => annex.buildingUniqueIds.length === 0)
    );
    console.log(label, "=>", hasEmpties);
}

check("all empty", {
    "entities": [
        {
            "annexes": [
                {
                    "buildingUniqueIds": []
                },
                {
                    "buildingUniqueIds": []
                },
                {
                    "buildingUniqueIds": []
                },
            ],
            "buildingUniqueIds": []
        }
    ]
});

check("none empty", {
    "entities": [
        {
            "annexes": [
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": [{}]
                },
            ],
            "buildingUniqueIds": [{}]
        }
    ]
});

check("entities.buildingUniqueIds empty", {
    "entities": [
        {
            "annexes": [
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": [{}]
                },
            ],
            "buildingUniqueIds": []
        }
    ]
});

check("entities.annexes.buildingUniqueIds[1] empty", {
    "entities": [
        {
            "annexes": [
                {
                    "buildingUniqueIds": [{}]
                },
                {
                    "buildingUniqueIds": []
                },
                {
                    "buildingUniqueIds": [{}]
                },
            ],
            "buildingUniqueIds": [{}]
        }
    ]
});

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-get-the-size-of-an-array-in-javascript
How to Get the Size of an Array in JavaScript - GeeksforGeeks
July 23, 2025 - // Defining an array const a = ... on a callback function. To get the size of an array, reduce() increments an accumulator for each element, returning the final count....
🌐
MSR
rajamsr.com › home › javascript object length: how to master it in 10 minutes
JavaScript Object Length: How to Master It in 10 Minutes | MSR - Web Dev Simplified
March 13, 2024 - Since the book object has a non-enumerable property, the output, in this case, is 1.We then used the Object.keys() method to get an array of the object’s enumerable property names, and we checked the length of the array.
🌐
SamanthaMing
samanthaming.com › tidbits › 56-how-to-get-an-object-length
How to Get an Object Length | SamanthaMing.com
Object.keys return an array of all the object's enumerable property keys. And after that, you can simply call length, and voila! You have the length of the object 🎉 · const object = { one: '1️⃣', two: '2️⃣' }; // Using Lodash _.size(object); // 2 // Using JavaScript Object.keys(object).length; // 2 ·
🌐
EncodedNA
encodedna.com › javascript › how-to-get-the-length-of-an-object-in-javascript.htm
How to Get the Length of an Object in JavaScript
One of simplest and perhaps the quickest way to get the length of a given object in JavaScript is by using the length property of Object.keys() method. The Object.keys() method returns an array of object properties.
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › how to find the javascript array length
How to Find the JavaScript Array Length - Shiksha Online
December 18, 2023 - The JavaScript array length property indicates the number of objects in an array. Refer to the object array name to get an array's length.
🌐
Career Karma
careerkarma.com › blog › javascript › javascript array length: a complete guide
JavaScript Array Length: A Complete Guide | Career Karma
December 1, 2023 - The JavaScript array length property states the number of items in an array. To find the length of an array, reference the object array_name.length.
🌐
xjavascript
xjavascript.com › blog › find-length-size-of-an-array-in-javascript
How to Find the Length (Size) of an Array in JavaScript: Why Objects Return Undefined for .length — xjavascript.com
Arrays: .length is a special property that tracks the highest numeric index + 1. This works because array keys are numeric and ordered. Objects: Object keys are arbitrary (strings, Symbols, etc.) and unordered. There’s no universal definition of "size" for objects, so JavaScript doesn’t include a built-in .length property.