Page 1 of 1

How to count the number of elements in array?

Posted: Sat Aug 22, 2015 2:19 pm
by Makoto

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


How to count the number of elements in array?

Posted: Sat Aug 22, 2015 8:44 pm
by Illya Stepanov

Hi Makoto -

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


How to count the number of elements in array?

Posted: Sun Aug 23, 2015 1:41 pm
by Makoto

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


How to count the number of elements in array?

Posted: Tue Aug 25, 2015 6:59 am
by Serhii Kulibaba

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


How to count the number of elements in array?

Posted: Thu Aug 27, 2015 12:24 pm
by Makoto

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.


How to count the number of elements in array?

Posted: Sun Sep 06, 2015 4:02 pm
by Makoto

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...


How to count the number of elements in array?

Posted: Tue Sep 08, 2015 8:37 pm
by Serhii Kulibaba