Get cumulative length of array inside array of objects

I have been searching for quite a while but cannot find an answer to my issue. The problem is pretty simple; I have an array of objects, each containing another array of objects. I want to get the cumulative length of all arrays inside all objects.

Here is some sample data:

const items = [
    {
        id: 1,
        title: "Test 1",
        data: [
            {
                ...
            },
            {
                ...
            },
        ]
    },
    {
        id: 2,
        title: "Test 2",
        data: [
            {
                ...
            },
        ]
    }
]

In this sample, the length should be 3 since there is 2 objects inside the first object’s data property and 1 object inside the second object’s data property.

78 thoughts on “Get cumulative length of array inside array of objects”

Leave a Comment