1

I'm using a GET method to view a json file as follows.

$scope.train = function () {

            var url = 'http://localhost/heart/api/restApiController/dataset.json';

            $http({
                method: 'GET',
                url: url


            }).then(function (data) {

            });


        };

Now I want to count numberof objects in the json file.how can I do it?

log of data

Object {data: Array[5], status: 201, config: Object, statusText: "Created"}
config:Object
data:Array[5]
headers:(d)
status:201
statusText:"Created"

So there are 5 objects in this array.how can I get this value 5 from AngularJS code?

CraZyDroiD
  • 6,622
  • 30
  • 95
  • 182
  • see this http://stackoverflow.com/questions/28716541/how-to-count-map-size-in-angularjs and http://stackoverflow.com/questions/5223/length-of-a-javascript-object-that-is-associative-array – Hadi J May 22 '16 at 06:56

1 Answers1

4

You can simply use the standard length

data.data.length
  • so if I want to count the objects with specific values, how can I do it? Ex: I want to count the objects with weight: "2" How to do this? – CraZyDroiD May 22 '16 at 06:55
  • As you are using angularjs, you could use `filter` and then `length` on the returned array, see [filter](https://docs.angularjs.org/api/ng/filter/filter) – Andreas Scheibleger May 22 '16 at 07:11