Makoto
Posts: 0
Joined: Fri Oct 10, 2014 8:15 am

How to count the number of elements in array?

Hi, appery support team!

I have the following database object, request, and response. I want to get how many elements does each object have. So, I set the following JavaScript code at Success event, but it doesn't work.Could you give me advice?

Thank you!

return value.length;

※ In this case, I want to receive the value of 2.

Image

Image

Image

Image

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

How to count the number of elements in array?

Hi Makoto -

Add console.log() to your code and check in the browser console what result is returned upon calling this mapping.

Makoto
Posts: 0
Joined: Fri Oct 10, 2014 8:15 am

How to count the number of elements in array?

I checked it and the result was a specific value like 55486b8de4b03d3319f8ea54.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How to count the number of elements in array?

Hello Makoto,

Please use this JS:

prefor(var i = 0; i < data&#46;length; i++){
console&#46;log(i+" element has length: " + data&#46;length);
}/pre

Makoto
Posts: 0
Joined: Fri Oct 10, 2014 8:15 am

How to count the number of elements in array?

Hello Sergiy,

Thank you very much for your help.
Now I'm trying to embed your cord into my cord.
I will reply as soon as possible.

Makoto
Posts: 0
Joined: Fri Oct 10, 2014 8:15 am

How to count the number of elements in array?

Is it possible to use $size (Array Aggregation Operator) in order to count and return the total number of items in an array?

cf. https://docs.mongodb.org/master/refer...

Return to “Issues”