Count number of Objects

Hi,

I'm trying to get the number of objects from a query but am failing to get the syntax correct.

As you can see it sees 2 Objects
Screenshot 2022-11-02 at 15.32.11

And even the UI tells me there's 2 keys in the parent object, but I can't seem to get this value into the query. I've tried the obvious .length etc but can't get it.

Screenshot 2022-11-02 at 15.32.35

This is to dynamically drive the number of rows in a listView.

Cheers,
Dave.

in the query you can use a transformer to format what is returned to be an array
{{formatDataAsArray(data)}}

Then you can use query1.data.Item.sites.length

Hmm that didn't seem to work. When I run the query without the transformer I get this returned
Screenshot 2022-11-02 at 18.33.46

But when I add the transformer I get nothing returned

Is it because I'm doing a getItem Method?

If you're looking to grab the number of Objects from "Item.sites", which is expected to evaluate to 2, then you can use the Object.keys() method which will return an array of all your keys, then tag on the .length method which will tell you how many keys you have.

This would look like: Object.keys(query1.data.Item.sites).length

Hope this helps!

1 Like